Custom Push Notification coming twice using Parse.com and Android -
i working in custom push notification using parse.com android. push integrated in application, problem getting 2 notifications @ time.
one custom receiver image , other 1 default notification os without image , notification not removing notification bar, if removing it, coming again , again on notification tray. paste code snippet , images below well.
// custom receiver class public class custompushreceiver extends parsepushbroadcastreceiver { private final string tag = custompushreceiver.class.getsimplename(); private notificationutils notificationutils; private intent parseintent; public custompushreceiver() { super(); } @override public void onreceive(context context, intent intent) { super.onpushreceive(context, intent); if (intent == null) return; parseintent = intent; try { string action = intent.getaction(); jsonobject json = new jsonobject(intent.getextras().getstring("com.parse.data")); if (action.equalsignorecase("com.parse.push.intent.receive")) { // notification_id++; string title = "dw"; if (json.has("alert")) { string text = json.getstring("alert"); generatenotification(context, title, json, text,parseintent); } } } catch (jsonexception e) { } } @override protected void onpushdismiss(context context, intent intent) { super.onpushdismiss(context, intent); } @override protected void onpushopen(context context, intent intent) { super.onpushopen(context, intent); } private void generatenotification(context context, string title, jsonobject json, string text, intent intent) { // intent intent = new intent(context, home.class); intent.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_task); pendingintent contentintent = pendingintent.getactivity(context, 0, intent, pendingintent.flag_one_shot); notificationmanager mnotifm = (notificationmanager) context.getsystemservice(context.notification_service); android.support.v4.app.notificationcompat.builder mbuilder = new notificationcompat.builder(context) .setsmallicon(r.drawable.log_pic_small) .setlargeicon(bitmapfactory.decoderesource(context.getresources(), r.drawable.log_pic)) .setautocancel(true) .setcontenttitle(title) .setcontenttext(text) .setstyle(new notificationcompat.bigtextstyle().bigtext(text)) .setticker(text) .setlights(color.green, 500, 500); mnotifm.cancel(0); mbuilder.setcontentintent(contentintent); mnotifm.notify(110, mbuilder.build()); } }
manifest file
<service android:name="com.parse.pushservice" /> <receiver android:name="com.restaurant.services.custompushreceiver" android:exported="false"> <intent-filter> <action android:name="android.intent.action.boot_completed" /> <action android:name="android.intent.action.user_present" /> <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" /> <!-- important: change "info.androidhive.parsenotifications" match app's package name. --> <category android:name="com.dw" /> </intent-filter> </receiver>
i think problem generated method super.onpushreceive(context, intent);
in public void onreceive(context context, intent intent)
.
i think should override protected void onpushreceive(context context,intent intent)
, handle push notification there. note: not call super if override onpushreceive
because display again push.
as per parse documentation:
called when push notification received. default, broadcast intent sent if "action" present in data , notification show if "alert" , "title" present in data.
edit
public class custompushreceiver extends parsepushbroadcastreceiver { ..... init code here exaple....
@override public void onreceive(context context, intent intent) { super.onreceive(context context, intent intent); } @override public void onpushreceive(context context, intent intent) { //no super call ....exact code onreceive..... } ... rest of code example...
}
i think can handle here.
Comments
Post a Comment