PhoneGap的/科尔多瓦日历集成(安卓) [英] PhoneGap/Cordova calendar integration (Android)

查看:103
本文介绍了PhoneGap的/科尔多瓦日历集成(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建设使用的PhoneGap(又名科尔多瓦)的Andr​​oid应用程序,和我遇到麻烦日历的整合工作。 免责声明:我是小白到Android和PhoneGap的,请多多包涵

I'm building an Android app using PhoneGap (aka Cordova), and am having trouble getting a calendar integration to work. Disclaimer: I'm a noob to both Android and PhoneGap, please bear with me.

所有我想要做的就是添加一个事件到用户的日历。继<一href="http://www.adobe.com/devnet/html5/articles/extending-phonegap-with-native-plugins-for-android.html"相对=nofollow>本教程,我创建了一个插件,尝试启动日历意图。在code是这样的:

All I'm trying to do is add an event to the user's calendar. Following this tutorial, I've created a Plugin that attempts to launch a Calendar Intent. The code looks like this:

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, 6, 19, 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");
}
}

JavaScript的code调用该插件是标准的:

The Javascript code to invoke this plugin is standard:

var CalendarPlugin = { 
    callNativeFunction: function (success, fail, resultType) { 
        if (cordova) {
            return cordova.exec( success, fail, 
                "org.myorg.appname.CalendarPlugin", 
                "addToCalendar", [resultType]);
        }
        else {
            alert("Calendar function is not available here.");
        }
    } 
};

而Android code是越来越援引(使用断点确认)。但发送回给Javascript code中的结果是错误的:

The Android code is getting invoked (confirmed using a breakpoint). But the result sent back to the Javascript code is an error:

找不到明确的活动类{org.myorg.appname / org.myorg.appname.CalendarPlugin};有你在你的Andr​​oidManifest.xml宣布这项活动?

Unable to find explicit activity class {org.myorg.appname/org.myorg.appname.CalendarPlugin}; have you declared this activity in your AndroidManifest.xml?

有没有提到增加的Andr​​oidManifest.xml中的教程,这使我相信,我失去了一些东西(也行, CalendarPlugin 的code被调用成功,所以怎么可能有是一个错误说法的 CalendarPlugin 的类不能被找到?)。如果确实是我需要添加的 CalendarPlugin 的到货单,我怎么会去这样做?

There's no mention of adding to AndroidManifest.xml in the tutorial, which leads me to believe I'm missing something (also, the CalendarPlugin code is being invoked successfully, so how could there be an error saying the CalendarPlugin class could not be found?). If indeed I need to add CalendarPlugin to the manifest, how would I go about doing that?

推荐答案

引不包括意向的教程。你发送你的数据,这样做的目的是你自己CalendarPlugIn类,是不是你想要的,因为它没有处理这个意图是什么。

The tutorial cited didn't cover intents. The intent you are sending your data to is your own CalendarPlugIn class which isn't what you want as it doesn't handle the intent.

请参阅 http://developer.android.com/guide/topics对于意图/intents/intents-filters.html

此外,如果你四处搜寻,所以你会发现,直到ICS甚至没有办法的事情添加到谷歌日历官方不使用Web服务。有办法非正式做到这一点,但仍可能受到谷歌的冲动或ODM厂商自己。

Also if you search around SO you'll find that until ICS there wasn't even a way to add things to the Google Calendar officially without using a web service. There are ways to do it unofficially, but are subject to the whims of Google or the ODMs themselves.

更新:

您应该可以(通过插件)使用意图与PhoneGap的。我只加了注释需要注意的是,如果你打算有日历集成在您的应用程序,你可能必须做一些研究,如果你想支持大部分Android设备。如果你有兴趣在ICS添加日历事件看:的http://开发商。 android.com/reference/android/provider/CalendarContract.html

You should be able to use intents with Phonegap (via a plugin). I only added the comment to note that if you intend to have calendar integration in your app, you'll probably have to do a bit of research if you want to support the majority of Android devices. If you are interested in adding calendar events in ICS look at: http://developer.android.com/reference/android/provider/CalendarContract.html

作品的修改

我只是需要修复的意图的构造函数,这和预期一样:

I just needed to fix the Intent constructor, and this worked as expected:

Uri uri = Uri.parse("content://com.android.calendar/events");
Intent calIntent = new Intent("android.intent.action.INSERT", uri)

这篇关于PhoneGap的/科尔多瓦日历集成(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆