java - Android Crash During Register Push Notifications -
i using gcm.jar push notifications. when start app trying register push notifications crashed.
06-04 10:08:32.479: e/broadcastreceiver(26774): broadcastreceiver trying return result during non-ordered broadcast 06-04 10:08:32.479: e/broadcastreceiver(26774): java.lang.runtimeexception: broadcastreceiver trying return result during non-ordered broadcast 06-04 10:08:32.479: e/broadcastreceiver(26774): @ android.content.broadcastreceiver.checksynchronoushint(broadcastreceiver.java:783) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ android.content.broadcastreceiver.setresult(broadcastreceiver.java:658) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ com.google.android.gcm.gcmbroadcastreceiver.onreceive(gcmbroadcastreceiver.java:56) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ android.app.activitythread.handlereceiver(activitythread.java:2394) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ android.app.activitythread.access$1500(activitythread.java:145) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ android.app.activitythread$h.handlemessage(activitythread.java:1322) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ android.os.handler.dispatchmessage(handler.java:99) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ android.os.looper.loop(looper.java:137) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ android.app.activitythread.main(activitythread.java:5095) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ java.lang.reflect.method.invokenative(native method) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ java.lang.reflect.method.invoke(method.java:511) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:898) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:665) 06-04 10:08:32.479: e/broadcastreceiver(26774): @ dalvik.system.nativestart.main(native method)
and menifest.xml is
<uses-permission android:name="android.permission.get_accounts" /> <uses-permission android:name="android.permission.wake_lock" /> <uses-permission android:name="com.google.android.c2dm.permission.receive" /> <uses-permission android:name="com.app.example.permission.c2d_message" /> <permission android:name="com.app.example.permission.c2d_message" android:protectionlevel="signature" /> <receiver android:name="com.google.android.gcm.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send" > <intent-filter> <!-- receives registration id. --> <action android:name="com.google.android.c2dm.intent.registration" /> <!-- receives actual messages. --> <action android:name="com.google.android.c2dm.intent.receive" /> <category android:name="com.app.example" /> </intent-filter> </receiver> <service android:name="com.app.example.gcmintentservice" />
my broadcastreciever code below
public class gcmintentservice extends gcmbaseintentservice { @suppresswarnings("hiding") private static final string tag = "gcmintentservice "; public gcmintentservice() { super(sender_id); } @override protected void onregistered(context context, string registrationid) { preferencemanager.getdefaultsharedpreferences(context).edit() .putstring("registration_key", registrationid).commit(); } @override protected void onunregistered(context context, string registrationid) { // debuger.e(tag, "device unregistered"); } @override protected void onmessage(context context, intent intent) { handlemessage(context, intent); } @override protected void ondeletedmessages(context context, int total) { } @override public void onerror(context context, string errorid) { } @override protected boolean onrecoverableerror(context context, string errorid) { // log message return super.onrecoverableerror(context, errorid); } private void handlemessage(context context, intent intent) { // whatever want message string order_id = intent.getstringextra("order_id"); string status_id = intent.getstringextra("status_id"); string message = intent.getstringextra("message"); if (!message.equals("")) { if (order_id != null && status_id != null & !status_id.equals("4")) { bundle bundle = new bundle(); bundle.putint("fromgetitem", 2); mainintent = new intent(context.getapplicationcontext(), mainactivity.class); mainintent.putextras(bundle); mainintent.setflags(intent.flag_activity_new_task); context.startactivity(mainintent); } generatenotification(context, message, mainintent); } } private static void generatenotification(context context, string message, intent notificationintent) { int icon = r.drawable.ic_launcher; long when = system.currenttimemillis(); notificationmanager notificationmanager = (notificationmanager) context .getsystemservice(context.notification_service); notification notification = new notification(icon, message, when); string title = context.getstring(r.string.app_name); pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, 0); notification.setlatesteventinfo(context, title, message, intent); notification.flags |= notification.flag_auto_cancel; // play default notification sound notification.defaults |= notification.default_sound; // vibrate if vibrate enabled notification.defaults |= notification.default_vibrate; notificationmanager.notify(0, notification); } }
how can fix crash?
i think getting , process messages
@override protected void onmessage(context context, intent intent) { handlemessage(context, intent); }
when app send request google registration of device don't know times google returns message if parsing messages , intent don't bundle , gives null app crash. can try below code may helps.
@override protected void onmessage(context context, intent intent) { //bundle[{cmd=rst_full, from=google.com/iid}] bundle bundle = intent.getextras(); if (bundle != null) { if (!bundle.containskey("cmd")) { handlemessage(context, intent); } } }
Comments
Post a Comment