C2DM / Phonegap plugin?

后端 未结 2 632
情深已故
情深已故 2021-01-06 20:52

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

相关标签:
2条回答
  • 2021-01-06 21:32

    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

    0 讨论(0)
  • 2021-01-06 21:53

    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.

    0 讨论(0)
提交回复
热议问题