[英]Dynamic broadcast registration for SMS_RECEIVED is not working
在AndroidManifest.xml
文件中为SMS_RECEIVED
操作注册广播接收器
<receiver android:name=".SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
如预期的那样工作,将SmsReceiver.onReceive(Context context, Intent intent)
。 尝试动态注册
Intent inte = registerReceiver(
new SmsReceiver(),
new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION));
永远不会调用SmsReceiver.onReceive(Context context, Intent intent)
。
注意
IntentFilter.setPriority(1000)
,但没有成功。 registerReceiver
返回null 我该如何解决?
我该如何解决?
首先使用正确的Intent
操作。
有两个与SMS传递相关的操作字符串。 SMS_RECEIVED_ACTION
适用于任何应用程序,以及您在<intent-filter>
中使用的SMS_RECEIVED_ACTION
。 SMS_DELIVER_ACTION
只对用户选择的SMS客户端有效,而您要与IntentFilter
一起使用。 这些不一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.