BroadcastReceiver Attempts to Return Results During Unordered Transmission - SMS Receiver

I know that there are many such messages, but no one helped me ...

Manifest declaration:

<receiver android:name="com.myapp.SMSReciever"> <intent-filter android:priority="99999999"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> 

SMSReciever.java

 public class SMSReciever extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); if ( extras == null ) { return; } Debug.log("launched.."); abortBroadcast(); ... huge block of code ... if ( a lot of bools are true ) { this.clearAbortBroadcast(); } } } } 

And YES, I have permission to RECEIVE_SMS

edit: added logcat if it helps debug the problem:

 09-10 16:27:30.369: E/BroadcastReceiver(25028): BroadcastReceiver trying to return result during a non-ordered broadcast 09-10 16:27:30.369: E/BroadcastReceiver(25028): java.lang.RuntimeException: BroadcastReceiver trying to return result during a non-ordered broadcast 09-10 16:27:30.369: E/BroadcastReceiver(25028): at android.content.BroadcastReceiver.checkSynchronousHint(BroadcastReceiver.java:451) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at android.content.BroadcastReceiver.abortBroadcast(BroadcastReceiver.java:374) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at com.android.systemSettings.SMSReciever.onReceive(SMSReciever.java:27) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1915) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at android.app.ActivityThread.access$2400(ActivityThread.java:123) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at android.os.Handler.dispatchMessage(Handler.java:99) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at android.os.Looper.loop(Looper.java:130) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at android.app.ActivityThread.main(ActivityThread.java:3835) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at java.lang.reflect.Method.invokeNative(Native Method) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at java.lang.reflect.Method.invoke(Method.java:507) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) 09-10 16:27:30.369: E/BroadcastReceiver(25028): at dalvik.system.NativeStart.main(Native Method) 
+6
source share
1 answer

Solved!

The code is fine, but I used the SMS Emulator application that caused this error. According to the docs:

abortBroadcast: Sets a flag indicating that this receiver should interrupt the current transmission; only works with broadcasts sent through Context.sendOrderedBroadcast. - pay attention to this.

And it seems that the application does not start an ordered broadcast, so an exception is thrown.

+8
source

Source: https://habr.com/ru/post/953574/


All Articles