Android: How to use Parse as an alternative GCM push notification provider? -
see edit#2 @ end of question (google updated way push implemented became easier handle gcm , parse together)
i use gcm inside application , add parse alternative. have (all permissions correctly declared):
<service android:name="com.mypackagename.gcmintentservice" android:enabled="true" /> <receiver android:name="com.google.android.gcm.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send" > <intent-filter> <action android:name="com.google.android.c2dm.intent.receive" /> <action android:name="com.google.android.c2dm.intent.registration" /> <category android:name="com.mypackagename.gcmintentservice" /> </intent-filter> </receiver>
the 'gcmintentservice' (inherits 'gcmbaseintentservice') class handles server registration , receiving of messages - works fine , push messages received. server sends custom data handle messages myself , create notifications programmatically (the intent used when notification clicked has important extras sent server).
i somehow make parse behave in same way in order able send channel pushes parse website , create own notifications, tried failed (following android push tutorial isn't working problem). there tried similar thing? i'm kind of out of ideas after spending lot of time tweaking push guides/tutorials - don't receive notifications; both parse , receiver called , double notifications. tried register using parse rest apis , handle myself found out isn't possible on android.
so, how handle both parse pushes , traditional gcm pushes (using server) in such way have access both notifications , can build them scratch (create own pending notifications required extras)?
edit#1:
the first thing tried use parse service , have single broadcast receiver handle gcm messages:
androidmaifest.xml:
<service android:name="com.mypackagename.gcmintentservice" android:enabled="true" /> <service android:name="com.parse.pushservice" android:enabled="true"/> <receiver android:name="com.google.android.gcm.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send" > <intent-filter> <action android:name="com.google.android.c2dm.intent.receive" /> <action android:name="com.google.android.c2dm.intent.registration" /> <category android:name="com.mypackagename.gcmintentservice" /> </intent-filter> </receiver>
and parse library requires following initializations:
parse.initialize(context, appid, apikey); pushservice.setdefaultpushcallback(context, mainactivity.class); // i'm subscribing channel push because send channel pushes // parse console pushservice.subscribe(context, mdconstants.parse_push_channel, mainactivity.class); parseinstallation.getcurrentinstallation().saveinbackground();
the problem receive notifications other provider don't receive parse (all permissions declared) , following error parse library (when receiving error parse registration not done - can't see device in parse console):
e/com.parse.manifestinfo(11677): cannot use gcm push because app manifest missing required declarations. please make sure these permissions declared children of root <manifest> element: e/com.parse.manifestinfo(11677): e/com.parse.manifestinfo(11677): <uses-permission android:name="android.permission.internet" /> e/com.parse.manifestinfo(11677): <uses-permission android:name="android.permission.access_network_state" /> e/com.parse.manifestinfo(11677): <uses-permission android:name="android.permission.vibrate" /> e/com.parse.manifestinfo(11677): <uses-permission android:name="android.permission.wake_lock" /> e/com.parse.manifestinfo(11677): <uses-permission android:name="android.permission.get_accounts" /> e/com.parse.manifestinfo(11677): <uses-permission android:name="com.google.android.c2dm.permission.receive" /> e/com.parse.manifestinfo(11677): <permission android:name="com.mypackagename.permission.c2d_message" android:protectionlevel="signature" /> e/com.parse.manifestinfo(11677): <uses-permission android:name="com.mypackagename.permission.c2d_message" /> e/com.parse.manifestinfo(11677): e/com.parse.manifestinfo(11677): also, please make sure these services , broadcast receivers declared children of <application> element: e/com.parse.manifestinfo(11677): e/com.parse.manifestinfo(11677): <service android:name="com.parse.pushservice" /> e/com.parse.manifestinfo(11677): <receiver android:name="com.parse.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send"> e/com.parse.manifestinfo(11677): <intent-filter> e/com.parse.manifestinfo(11677): <action android:name="com.google.android.c2dm.intent.receive" /> e/com.parse.manifestinfo(11677): <action android:name="com.google.android.c2dm.intent.registration" /> e/com.parse.manifestinfo(11677): <category android:name="com.mypackagename" /> e/com.parse.manifestinfo(11677): </intent-filter> e/com.parse.manifestinfo(11677): </receiver> e/com.parse.pushservice(11677): tried use push, app not configured push due to: push not configured app because app manifest missing required declarations. please add following declarations app manifest support either gcm or ppns push (or both). enable gcm support, please make sure these permissions declared children of root <manifest> element: e/com.parse.pushservice(11677): e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.internet" /> e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.access_network_state" /> e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.vibrate" /> e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.wake_lock" /> e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.get_accounts" /> e/com.parse.pushservice(11677): <uses-permission android:name="com.google.android.c2dm.permission.receive" /> e/com.parse.pushservice(11677): <permission android:name="com.mypackagename.permission.c2d_message" android:protectionlevel="signature" /> e/com.parse.pushservice(11677): <uses-permission android:name="com.mypackagename.permission.c2d_message" /> e/com.parse.pushservice(11677): e/com.parse.pushservice(11677): also, please make sure these services , broadcast receivers declared children of <application> element: e/com.parse.pushservice(11677): e/com.parse.pushservice(11677): <service android:name="com.parse.pushservice" /> e/com.parse.pushservice(11677): <receiver android:name="com.parse.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send"> e/com.parse.pushservice(11677): <intent-filter> e/com.parse.pushservice(11677): <action android:name="com.google.android.c2dm.intent.receive" /> e/com.parse.pushservice(11677): <action android:name="com.google.android.c2dm.intent.registration" /> e/com.parse.pushservice(11677): <category android:name="com.mypackagename" /> e/com.parse.pushservice(11677): </intent-filter> e/com.parse.pushservice(11677): </receiver> e/com.parse.pushservice(11677): enable ppns support, please make sure these permissions declared children of root <manifest> element: e/com.parse.pushservice(11677): e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.internet" /> e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.access_network_state" /> e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.receive_boot_completed" /> e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.vibrate" /> e/com.parse.pushservice(11677): <uses-permission android:name="android.permission.wake_lock" /> e/com.parse.pushservice(11677): e/com.parse.pushservice(11677): also, please make sure these services , broadcast receivers declared children of <application> element: e/com.parse.pushservice(11677): e/com.parse.pushservice(11677): <service android:name="com.parse.pushservice" /> e/com.parse.pushservice(11677): <receiver android:name="com.parse.parsebroadcastreceiver"> e/com.parse.pushservice(11677): <intent-filter> e/com.parse.pushservice(11677): <action android:name="android.intent.action.boot_completed" /> e/com.parse.pushservice(11677): <action android:name="android.intent.action.user_present" /> e/com.parse.pushservice(11677): </intent-filter> e/com.parse.pushservice(11677): </receiver>
edit#2:
i updated way gcm push handled based on google push notification developer guide. while implementing class extends 'gcmlistenerservice', can check if 'from' arguments same google project id used register push.
public class mygcmlistenerservice extends gcmlistenerservice { @override public void onmessagereceived(string from, bundle data) { // handle gcm messages come same project id used register if (from.equals("your google project id)) { // handle gcm push } } }
also, parse updated libraries (i'm using '1.9.4' right now) , can subclass 'parsepushbroadcastreceiver' handle notifications you'd like. see guide here basic implementation.
parse initialization in 'oncreate' method of 'application' class:
parse.initialize(this, "your parse app id", "your parse client key"); // subscribing channel parsepush.subscribeinbackground("your channel name", new savecallback() { @override public void done(parseexception e) { if (e == null) { log.d("com.parse.push", "successfully subscribed broadcast channel."); } else { log.e("com.parse.push", "failed subscribe push"); } } });
the broadcast receiver implementation:
public class myparsepushbroadcastreceiver extends parsepushbroadcastreceiver { @override protected void onpushreceive(context context, intent intent) { // handle parse push notification } }
the manifest declaration both parse , gcm:
... <!-- gcm listener service --> <service android:name=".mygcmlistenerservice" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.receive" /> </intent-filter> </service> ... <!-- parse broadcast receiver --> <receiver android:name=".myparsepushbroadcastreceiver" android:exported="false"> <intent-filter> <action android:name="com.parse.push.intent.receive" /> <action android:name="com.parse.push.intent.delete" /> <action android:name="com.parse.push.intent.open" /> </intent-filter> </receiver> ...
i added service , receiver, need make sure follow gcm guide , parse push guides have full implementation (for example, google added way handle token refresh - sample containing full code samples can found here).
if understand correctly, want code handle incoming gcm messages, regardless of source (which can either server or parse website), means don't want parse code in app handle them.
you can achieve declaring single broadcast receiver handling com.google.android.c2dm.intent.receive
action in manifest. gcmbroadcastreceiver
class, handle arriving gcm messages.
the behavior experiencing can happen when declare 2 broadcast receivers handle same action.
Comments
Post a Comment