信不过你开车
信不过你开车
  • 发布:2015-05-07 12:46
  • 更新:2022-08-21 20:31
  • 阅读:26808

分享一个Android原生日历提醒插入案例。。。求个iOS的??谢谢。。。。。

分类:Native.js

一个简单的原生日历提醒插入。。。。native.js调用原生实现。。。。

<!DOCTYPE html>  
<html>  

    <head>  
        <meta charset="utf-8">  
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
        <title></title>  
        <script src="js/mui.min.js"></script>  
        <link href="css/mui.min.css" rel="stylesheet" />  
        <script type="text/javascript" charset="utf-8">  
            mui.init();  
        </script>  
    </head>  

    <body>  
        <button onclick="addEvent()"> 插入事件</button>  
    </body>  
    <script>  
        var calanderURL = "content://com.android.calendar/calendars";  
        var calanderEventURL = "content://com.android.calendar/events";  
        var calanderRemiderURL = "content://com.android.calendar/reminders";  
        var calId;  

        function addEvent() {  
                var Cursor = plus.android.importClass("android.database.Cursor");  
                var Uri = plus.android.importClass("android.net.Uri");  
                var Calendar = plus.android.importClass("java.util.Calendar");  
                var main = plus.android.runtimeMainActivity();  
                var userCursor = plus.android.invoke(main.getContentResolver(), "query", Uri.parse(calanderURL), null, null, null, null);  
                if (plus.android.invoke(userCursor, "getCount") <= 0) {  
                    console.log("添加账号" + plus.android.invoke(userCursor, "getCount"));  
                    initCalendars();  
                } else {  
                    console.log("开始插入:" + plus.android.invoke(userCursor, "getCount"));  
                    plus.android.invoke(userCursor, "moveToLast");  
                    calId = plus.android.invoke(userCursor, "getString", plus.android.invoke(userCursor, "getColumnIndex", "_id"));  
                    var ContentValues = plus.android.importClass("android.content.ContentValues");  
                    var events = new ContentValues();  
                    events.put("title", "测试中==》呵呵");  
                    events.put("description", "Frankie受空姐邀请,今天晚上10点以后将在Sheraton交流.lol~");  
                    // 插入账户  
                    events.put("calendar_id", calId);  
                    console.log(calId);  
                    events.put("eventLocation", "地球-华夏");  
                    var mCalendar = Calendar.getInstance();  
                    plus.android.invoke(mCalendar, "set", Calendar.HOUR_OF_DAY, 11);  
                    plus.android.invoke(mCalendar, "set", Calendar.MINUTE, 0);  
                    var start = plus.android.invoke(plus.android.invoke(mCalendar, "getTime"), "getTime");  
                    var end = plus.android.invoke(plus.android.invoke(mCalendar, "getTime"), "getTime");  
                    events.put("dtstart", start);  
                    events.put("dtend", end);  
                    events.put("hasAlarm", 1);  
                    events.put("eventTimezone", "Asia/Shanghai"); // 这个是时区,必须有,  
                    // 添加事件    
                    var newEvent = plus.android.invoke(plus.android.runtimeMainActivity().getContentResolver(), "insert", Uri.parse(calanderEventURL), events);  
                    // 事件提醒的设定  
                    var id = plus.android.invoke(newEvent, "getLastPathSegment");  
                    var values = new ContentValues();  
                    values.put("event_id", id);  
                    // 提前10分钟有提醒  
                    values.put("minutes", "10");  
                    values.put("method", "1");  
                    plus.android.invoke(main.getContentResolver(), "insert", Uri.parse(calanderRemiderURL), values);  
                    mui.toast("插入事件成功,可打开本地日历查看");  
                }  
            }  
            //添加账户  

        function initCalendars() {  
            var TimeZone=plus.android.importClass("java.util.TimeZone");  
            var timeZone = TimeZone.getDefault();  
            var  ContentValues=plus.android.importClass("android.content.ContentValues");     
            var value = new ContentValues();  
            var Calendars=plus.android.importClass("android.provider.CalendarContract.Calendars");  
            value.put("name", "yy");  
            value.put("account_name", "hehe@gmail.com");  
            value.put("account_type", "com.android.exchange");  
            value.put("calendar_displayName", "mytt");  
            value.put("visible", 1);  
            value.put("calendar_color", -9206951);  
            value.put("calendar_access_level","700");  
            value.put("sync_events", 1);  
            value.put("calendar_timezone",plus.android.invoke(timeZone, "getID"));  
            value.put("ownerAccount","hehe@gmail.com");  
            value.put("canOrganizerRespond", 0);  
            var Uri=plus.android.importClass("android.net.Uri");  
            var calendarUri=Uri.parse("content://com.android.calendar/calendars");  
            var buildUpon = plus.android.invoke(calendarUri, "buildUpon");  
            var CalendarContract = plus.android.importClass("android.provider.CalendarContract");  
            plus.android.invoke(buildUpon, "appendQueryParameter", CalendarContract.CALLER_IS_SYNCADAPTER, "true");  
            plus.android.invoke(buildUpon, "appendQueryParameter", "account_name", "hehe@gmail.com");  
            plus.android.invoke(buildUpon, "appendQueryParameter", "account_type", "com.android.exchange");  
            calendarUri = plus.android.invoke(buildUpon, "build");  
            plus.android.invoke(plus.android.runtimeMainActivity().getContentResolver(), "insert", calendarUri, value);  
            mui.toast("添加账号成功");  
        }  
    </script>  

</html>
9 关注 分享
藏马 DCloud_heavensoft BoredApe 若末lan 菜鸡 8***@qq.com 亲亲范er Meier user_name

要回复文章请先登录注册

8***@qq.com

8***@qq.com

看着这么多人维护着相同的热爱,当真热泪盈眶
2022-08-21 20:31
1***@qq.com

1***@qq.com

引的两个js在哪里能找到
2021-08-09 11:44
FullStack

FullStack

日历、提醒事项 添加日程和提醒(ios):[https://ext.dcloud.net.cn/plugin?id=5203](https://ext.dcloud.net.cn/plugin?id=5203)
2021-05-31 15:39
9***@qq.com

9***@qq.com

亲测小米华为手机调用一直添加账户
2021-05-13 11:14
1***@163.com

1***@163.com

andrind 对日历的增删改查 https://www.cnblogs.com/csdcs/p/13754214.html
2020-09-30 14:20
DCloud_heavensoft

DCloud_heavensoft

iOS的原生插件:https://ext.dcloud.net.cn/search?q=%E6%B7%BB%E5%8A%A0%E6%97%A5%E5%8E%86
2020-03-27 18:29
大漠苍狼woft

大漠苍狼woft

Uncaught java.lang.SecurityException: Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{ea3bca6 30545:io.dcloud.HBuilder/u0a136} (pid=30545, uid=10136) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR;at android.app.ContextImpl$ApplicationContentResolver.query at test.html 这是什么情况?
2019-09-26 14:40
瑶瑶

瑶瑶

这个在uni-app的项目工程下应该怎么运用????
2019-02-05 14:53
拜仁已伤

拜仁已伤

打包是不行的
2018-10-11 11:09
郁桦杰

郁桦杰

求IOS的日程提醒
2018-05-22 12:24