android - PushWoosh - add custom broadcast receiver -
what want achieve: upon receiving pushwoosh notification, check payload , direct user specific activity accordingly.
i'm following example in pushwoosh faq section regarding
using custom push broadcast receiver in android
however, i'm unable receive push inside custom push..
here's androidmanifest.xml
:
<receiver android:name="com.google.android.gcm.gcmbroadcastreceiver" android:exported="true" 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="${applicationid}" /> </intent-filter> </receiver> <receiver android:name=".receivers.pwbroadcastreceiver"> <intent-filter> <action android:name="${applicationid}.com.arellomobile.android.push.register_broad_cast_action"/> </intent-filter> </receiver> <service android:name="com.arellomobile.android.push.pushgcmintentservice" />
this custom broadcast receiver:
public class pwbroadcastreceiver extends broadcastreceiver { private static final string tag = "pwbroadcastreceiver"; @override public void onreceive(context context, intent intent) { if (intent == null) return; // let pushwoosh sdk pre-handling push (pushwoosh track stats, opens rich pages, etc.). // return bundle push notification data bundle pushbundle = pushmanager.prehandlepush(context, intent); if (pushbundle == null) return; // push bundle json object jsonobject dataobject = pushmanager.bundletojson(pushbundle); // default launcher intent clarity intent launchintent = context.getpackagemanager().getlaunchintentforpackage(context.getpackagename()); launchintent.addcategory("android.intent.category.launcher"); launchintent.setflags(intent.flag_activity_new_task | intent.flag_activity_reset_task_if_needed); // put push notifications payload in intent launchintent.putextras(pushbundle); launchintent.putextra(pushmanager.push_receive_event, dataobject.tostring()); // start activity! context.startactivity(launchintent); // let pushwoosh sdk post-handle push (track stats, etc.) pushmanager.posthandlepush(context, intent); } }
remote intent filter pwbroadcastreceiver, don't need it.
i don't see meta tags in androidmanifest.xml
you need add receiver name meta-data tag androidmanifest.xml, otherwise sdk doesn't know route push notification.
<receiver android:name=".receivers.pwbroadcastreceiver" /> <meta-data android:name="pw_notification_receiver" android:value=".receivers.pwbroadcastreceiver"/>
update: note
pw_notification_receiver
expectpackage + [path notification receiver class]
.. if use application_id (com.myapp.staging) different original package name (com.myapp), may cause problem.. , fix use original package instead of application id
Comments
Post a Comment