[英]Dynamic broadcast registration for SMS_RECEIVED is not working
Registering broadcast receiver for SMS_RECEIVED
action in AndroidManifest.xml
file 在
AndroidManifest.xml
文件中为SMS_RECEIVED
操作注册广播接收器
<receiver android:name=".SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
works as expected, SmsReceiver.onReceive(Context context, Intent intent)
is called. 如预期的那样工作,将
SmsReceiver.onReceive(Context context, Intent intent)
。 Trying to register dyamically 尝试动态注册
Intent inte = registerReceiver(
new SmsReceiver(),
new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION));
SmsReceiver.onReceive(Context context, Intent intent)
is never called. 永远不会调用
SmsReceiver.onReceive(Context context, Intent intent)
。
notice 注意
IntentFilter.setPriority(1000)
with no success. IntentFilter.setPriority(1000)
,但没有成功。 registerReceiver
returns null registerReceiver
返回null How can i fix that ? 我该如何解决?
How can i fix that ?
我该如何解决?
Start by using the correct Intent
action. 首先使用正确的
Intent
操作。
There are two action strings related to SMS delivery. 有两个与SMS传递相关的操作字符串。 What works for any app — and what you are using in the
<intent-filter>
— is SMS_RECEIVED_ACTION
. SMS_RECEIVED_ACTION
适用于任何应用程序,以及您在<intent-filter>
中使用的SMS_RECEIVED_ACTION
。 What only works for the user's chosen SMS client — and what you are trying to use with the IntentFilter
— is SMS_DELIVER_ACTION
. SMS_DELIVER_ACTION
只对用户选择的SMS客户端有效,而您要与IntentFilter
一起使用。 These are not the same. 这些不一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.