android - BroadcastReceiver trying to return result during a non-ordered broadcast Weird Error -
this error started occurring when app launched first time though not sending push notification:
broadcastreceiver trying return result during non-ordered broadcast java.lang.runtimeexception: broadcastreceiver trying return result during non-ordered broadcast @ android.content.broadcastreceiver.checksynchronoushint(broadcastreceiver.java:799) @ android.content.broadcastreceiver.setresultcode(broadcastreceiver.java:565) @ com.pushnotification.gcmbroadcastreceiver.onreceive(gcmbroadcastreceiver.java:17) @ android.app.activitythread.handlereceiver(activitythread.java:2712) @ android.app.activitythread.access$1700(activitythread.java:144) @ android.app.activitythread$h.handlemessage(activitythread.java:1449) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:155) @ android.app.activitythread.main(activitythread.java:5696) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1028) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:823)
the code broadcastreceiver:
public class gcmbroadcastreceiver extends wakefulbroadcastreceiver { @override public void onreceive(context context, intent intent) { // explicitly specify gcmintentservice handle intent. componentname comp = new componentname(context.getpackagename(), gcmintentservice.class.getname()); // start service, keeping device awake while launching. startwakefulservice(context, (intent.setcomponent(comp))); /* crash pointing line */ setresultcode(activity.result_ok); } }
the error started showing after implemented following code in intentservice (also doesn't called on app launch). not every time, i.e. after uninstalling , running app android studio error occurs , doesn't.
broadcastreceiver receiver; public void downloadlistener(final string zipfile) { receiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { string action = intent.getaction(); if (downloadmanager.action_download_complete.equals(action)) { long downloadid = intent.getlongextra(downloadmanager.extra_download_id, 0); downloadmanager.query query = new downloadmanager.query(); query.setfilterbyid(downloadreference); cursor c = downloadmanager.query(query); if (c.movetofirst()) { int columnindex = c.getcolumnindex(downloadmanager.column_status); if (downloadmanager.status_successful == c.getint(columnindex)) { dismissprogressdialog(); showprogress("almost done", "unzipping , installing database", pd.style_spinner); } } } } }; context.registerreceiver(receiver, new intentfilter(downloadmanager.action_download_complete)); }
in manifest:
<receiver android:name="com.pushnotification.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send" > <intent-filter> <action android:name="com.google.android.c2dm.intent.receive" /> <category android:name="com.geovision.ffmsnativeprototype" /> </intent-filter> </receiver> <service android:name=".webservicecommunication.systemdatabaseservice" />
after commenting out line setresultcode(activity.result_ok);
recommended answer another question intentservice push notification received notification content
from-google.com/iid-title-null-message-null-extradata-null
my case same weird push message received on app start
according answer https://stackoverflow.com/a/30508934/1950784
this google related feature not big deal , can filtered programatically.
@override protected void onhandleintent(intent intent) //receive pushnotification { bundle extras = intent.getextras(); googlecloudmessaging gcm = googlecloudmessaging.getinstance(this); // getmessagetype() intent parameter must intent received // in broadcastreceiver. string messagetype = gcm.getmessagetype(intent); if (!extras.isempty()) { // has effect of unparcelling bundle /* * filter messages based on message type. since gcm * extended in future new message types, ignore * message types you're not interested in, or don't * recognize. */ if (googlecloudmessaging. message_type_send_error.equals(messagetype)) { // sendnotification("send error: " + extras.tostring()); } else if (googlecloudmessaging. message_type_deleted.equals(messagetype)) { // sendnotification("deleted messages on server: " + // extras.tostring()); // if it's regular gcm message, work. } else if (googlecloudmessaging. message_type_message.equals(messagetype)) { log.i(tag, "pushnotification received @ " + systemclock.elapsedrealtime()); extradata=extras.getstring("extradata"); from=extras.getstring("from"); title=extras.getstring("title"); message=extras.getstring("message"); log.i(tag, "received: " + extras.tostring()+" m"+messagetype); if(title!=null) {
if(from.equals("google.com/iid")) { //related google ... not perform action } else { //handle received notification }
Comments
Post a Comment