C2DM / Phonegap 插件?

发布于 2024-12-27 08:34:40 字数 186 浏览 0 评论 0原文

我想将推送消息添加到我的 Phonegap Android 应用程序中,并相信 C2DM 是实现这项工作的最佳方式 - 可以为我指明正确的方向来设置它吗? 有插件或教程可以帮助解决这个问题吗?

另外 - 我真的需要一个插件吗 - 是否可以以传统的 Android 方式将 C2dm 添加到我的应用程序中,而不会弄乱我的phonegap 设置?

I would like to add Push messaging to my Phonegap Android App and believe that C2DM is the waybest way to make this work - could point me in the right direction to set this up?
Is there a plugin or tutorial to help with this?

Also - do I actually need a plugin - is it possible to add C2dm to my app the traditional Android way without messing up my phonegap setup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九厘米的零° 2025-01-03 08:34:40

是的,C2DM 就是 Android Push 解决方案。在 https://github.com/awysocki/C2DM-PhoneGap 上,您可以找到示例实现。

com.google 命名空间中的文件必须保持不变,它们来自会话“Google IO 会话概述:Android + App Engine:开发人员的梦想组合”,请参阅 http://bradabrams.com/2011/05/google-io-session-overview-android-app-engine-a-developers-dream-combination/

所以这些是您的步骤应该执行:

  1. 将 3 个 com.google 类添加到您的项目中
  2. 创建一个名为 C2DMReceiver 的类(命名约定),该类继承自 C2DMBaseReceiver 并实现必要的功能抽象事件
  3. 设置 AndroidManifest.xml

AndroidManifest 看起来像

<!-- set up an own permission to secure our C2DM mesages -->
<permission android:name="your.namespace.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />

<!-- List of permission -->
<uses-permission android:name="your.namespace.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application ..>

    <!-- Your implementation of the class C2DMReceiver, base class is Googles C2DMBaseReceiver -->
    <service android:name=".C2DMReceiver" />

    <!-- Googles broadcast receiver, it delegates to your.namespace.C2DMReceiver -->
    <receiver
            android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="your.namespace" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="your.namespace" />
        </intent-filter>
    </receiver>
</application>

如果您在模拟器上收到错误“E/CSE 通知(401):注册错误 ACCOUNT_MISSING”,则必须将 Google 帐户添加到您的模拟器。

对于你的第二个问题:这取决于你想做什么。当您收到消息并且只想显示通知以便用户能够启动您的应用程序时,您不需要 Phonegap 插件。那么一切都可以用java来解决。

Yes, C2DM is the Android Push solution. On https://github.com/awysocki/C2DM-PhoneGap you can find an example implementation.

The files in the com.google namespace have to be included unchanged, they are from the session "Google IO Session Overview: Android + App Engine: A Developer’s Dream Combination", see http://bradabrams.com/2011/05/google-io-session-overview-android-app-engine-a-developers-dream-combination/

So these are the steps you should perform:

  1. Add the 3 com.google classes to your project
  2. Create a class called C2DMReceiver (naming convention) which inherits from C2DMBaseReceiver and implement the necessary abstract events
  3. Set up the AndroidManifest.xml

The AndroidManifest looks like

<!-- set up an own permission to secure our C2DM mesages -->
<permission android:name="your.namespace.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />

<!-- List of permission -->
<uses-permission android:name="your.namespace.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application ..>

    <!-- Your implementation of the class C2DMReceiver, base class is Googles C2DMBaseReceiver -->
    <service android:name=".C2DMReceiver" />

    <!-- Googles broadcast receiver, it delegates to your.namespace.C2DMReceiver -->
    <receiver
            android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="your.namespace" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="your.namespace" />
        </intent-filter>
    </receiver>
</application>

If you receive on the emulator the error "E/CSE Notifications(401): Registration error ACCOUNT_MISSING", you have to add a Google account to your emulator.

For your second question: it depends what you want to do. When you receive the message and you just want to display a notification so that the user is able to start your app then you don't need a Phonegap plugin. In that case you can solve everything in java.

银河中√捞星星 2025-01-03 08:34:40

如果您得到这个答案,请注意 C2DM 已经过时,现在您必须使用 GCM。

此外,还有一个官方的 PhoneGap 插件支持 Android 和 iPhone 的通知。查看 PushPlugin:https://github.com/phonegap-build/PushPlugin

In case you get to this answer, notice C2DM is absolete and now you have to use GCM.

Moreover there is an official PhoneGap plugin supporting notification for both Android and iPhone. Check out the PushPlugin at https://github.com/phonegap-build/PushPlugin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文