android activity - how to open different activities when receiving notification from parse -
i have different categories in app such news,weather,sports and technology,i use parse receive notification ,but want notification customized in once notification regarding news received should open news activity,if notification regarding technology received should open technology activity. don't want custom push receiver,i tried lots of examples can't it.any ideas in advance
first need create custom class extends parsepushbroadcastreceiver. , in class override onpushopen method:
public class parsepushcustomreceiver extends parsepushbroadcastreceiver { protected static string pushtitle=""; @override protected void onpushopen(context context, intent intent) { super.onpushopen(context, intent); pushtitle=""; try { bundle extras = intent.getextras(); if (extras != null) { string jsondata = extras.getstring("com.parse.data"); jsonobject json; json = new jsonobject(jsondata); pushtitle = json.getstring("title"); string pushcontent = json.getstring("alert"); //intent activity } } catch (jsonexception e) { e.printstacktrace(); } } }
now when have title , content of push can direct activity want go...
you need define custom parsepushbroadcastreceiver reciever in androidmanifest.xml:
<!-- parse pushservice--> <service android:name="com.parse.pushservice" /> <receiver android:name="com.parse.parsebroadcastreceiver"> <intent-filter> <action android:name="android.intent.action.boot_completed" /> <action android:name="android.intent.action.user_present" /> </intent-filter> </receiver> <receiver android:name="com.appname.appname.parsepushcustomreceiver" 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> <receiver android:name="com.parse.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.appname.appname" /> </intent-filter> </receiver>
Comments
Post a Comment