广播接收器试图非有序的广播时,返回的结果 - 短信接收器 [英] BroadcastReceiver trying to return result during a non-ordered broadcast - SMS Receiver
问题描述
我知道有这样的帖子很多,但没有帮助我...
我的舱单申报:
<接收机器人:名字=com.myapp.SMSReciever>
<意向过滤器的android:优先=99999999>
<作用机器人:名字=android.provider.Telephony.SMS_RECEIVED/>
&所述; /意图滤光器>
< /接收器>
SMSReciever.java
公共类SMSReciever扩展广播接收器{
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
捆绑额外= intent.getExtras();
如果(演员== NULL){
返回;
} 的debug.log(推出..);
abortBroadcast(); ... code的巨大的块... 如果(很多的bool为真){
this.clearAbortBroadcast();
}
}
}
}
是的,我有权限 RECEIVE_SMS
编辑:
加入logcat的如果它可以帮助调试问题:
09-10 16:27:30.369:E /广播接收器(25028):广播接收器尝试一种无序播放过程中返回结果
09-10 16:27:30.369:E /广播接收器(25028):了java.lang.RuntimeException:广播接收器尝试一种无序播放过程中返回结果
09-10 16:27:30.369:E /广播接收器(25028):在android.content.BroadcastReceiver.checkSynchronousHint(BroadcastReceiver.java:451)
09-10 16:27:30.369:E /广播接收器(25028):在android.content.BroadcastReceiver.abortBroadcast(BroadcastReceiver.java:374)
09-10 16:27:30.369:E /广播接收器(25028):在com.android.systemSettings.SMSReciever.onReceive(SMSReciever.java:27)
09-10 16:27:30.369:E /广播接收器(25028):在android.app.ActivityThread.handleReceiver(ActivityThread.java:1915)
09-10 16:27:30.369:E /广播接收器(25028):在android.app.ActivityThread.access $ 2400(ActivityThread.java:123)
09-10 16:27:30.369:E /广播接收器(25028):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:989)
09-10 16:27:30.369:E /广播接收器(25028):在android.os.Handler.dispatchMessage(Handler.java:99)
09-10 16:27:30.369:E /广播接收器(25028):在android.os.Looper.loop(Looper.java:130)
09-10 16:27:30.369:E /广播接收器(25028):在android.app.ActivityThread.main(ActivityThread.java:3835)
09-10 16:27:30.369:E /广播接收器(25028):在java.lang.reflect.Method.invokeNative(本机方法)
09-10 16:27:30.369:E /广播接收器(25028):在java.lang.reflect.Method.invoke(Method.java:507)
09-10 16:27:30.369:E /广播接收器(25028):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:864)
09-10 16:27:30.369:E /广播接收器(25028):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
09-10 16:27:30.369:E /广播接收器(25028):在dalvik.system.NativeStart.main(本机方法)
解决了!
在code是还好吧,但我使用导致了这一错误的应用程序称为SMS模拟器。根据文档:
abortBroadcast:
设置指示,该接收器应该退出当前广播的标志;只有通过 Context.sendOrderedBroadcast
发送广播作品 - 注意到这一点
和似乎应用犯规发起一个有序的广播,从而抛出异常。
I know there are a LOT of posts like this, but none helped me...
My 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 the permission to RECEIVE_SMS
edit: added the logcat if it helps to debug the issue:
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)
Solved!
The code is allright, but I was using an app called SMS Emulator which caused this error. According to the docs:
abortBroadcast:
Sets the flag indicating that this receiver should abort the current broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast.
- notice this.
And it seems that the app doesnt launch an ordered broadcast, thus the exception is thrown.
这篇关于广播接收器试图非有序的广播时,返回的结果 - 短信接收器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!