大佬教程收集整理的这篇文章主要介绍了PhoneGap / Cordova日历集成(Android),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我要做的就是在用户的日历中添加一个事件.在this tutorial之后,我创建了一个试图启动Calendar Intent的插件.代码如下所示:
public class CalendarPlugin extends Plugin { public static final String NATIVE_ACTION_StriNG="addToCalendar"; public static final String succesS_PARAMETER="success"; @Override public PluginResult execute(String action,JSONArray data,String callBACkId) { if (NATIVE_ACTION_StriNG.equals(action)) { Calendar beginTime = Calendar.geTinstance(); beginTime.set(2012,6,19,7,30); Calendar endTime = Calendar.geTinstance(); endTime.set(2012,8,30); Intent calIntent = new Intent((Context) this.ctx,CalendarPlugin.class) .setAction(Intent.ACTION_INSERT) .putExtra(Events.titlE,"A new event") .putExtra(CalendarContract.EXTRA_EVENT_all_DAY,truE) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,beginTime.getTimeInMillis()) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME,endTime.getTimeInMillis()); this.ctx.startActivity(calIntent); return new PluginResult(PluginResult.Status.OK,"smashing success"); } return new PluginResult(PluginResult.Status.ERROR,"Didn't work bro"); } }
var CalendarPlugin = { callNativeFunction: function (success,fail,resultTypE) { if (cordova) { return cordova.exec( success,"org.myorg.appname.CalendarPlugin","addToCalendar",[resultType]); } else { alert("Calendar function is not available here."); } } };
Android代码被调用(使用断点确认).但结果发送回Javascript代码是一个错误:
没有提到在教程中添加到AndroidManifest.xml,这让我相信我遗漏了一些东西(同样,CalendarPlugin代码被成功调用,那么怎么会有错误说找不到CalendarPlugin类? ).如果我确实需要将CalendarPlugin添加到清单中,我该怎么做呢?
有关意图,请参阅http://developer.android.com/guide/topics/intents/intents-filters.html.
此外,如果您搜索SO,您会发现,直到ICS,甚至没有办法在不使用网络服务的情况下正式向Google日历添加内容.有很多方法可以非正式地进行,但是受到谷歌或ODM本身的影响.
更新:
您应该能够使用Phonegap(通过插件)使用意图.我只是添加了评论,请注意,如果您打算在应用中进行日历集成,那么如果您想支持大多数Android设备,您可能需要做一些研究.如果您有兴趣在ICS中添加日历活动,请查看:http://developer.android.com/reference/android/provider/CalendarContract.html
Op的编辑
我只需要修复Intent构造函数,这按预期工作:
Uri uri = Uri.parse("content://com.android.calendar/events"); Intent calIntent = new Intent("android.intent.action.INSERT",uri)
以上是大佬教程为你收集整理的PhoneGap / Cordova日历集成(Android)全部内容,希望文章能够帮你解决PhoneGap / Cordova日历集成(Android)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。