SMS_RECEIVED的动态广播注册不起作用 [英] Dynamic broadcast registration for SMS_RECEIVED is not working
问题描述
在AndroidManifest.xml
文件中为SMS_RECEIVED
操作注册广播接收器
Registering broadcast receiver for SMS_RECEIVED
action in AndroidManifest.xml
file
<receiver android:name=".SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
可以正常工作,将调用SmsReceiver.onReceive(Context context, Intent intent)
.
尝试动态注册
works as expected, SmsReceiver.onReceive(Context context, Intent intent)
is called.
Trying to register dyamically
Intent inte = registerReceiver(
new SmsReceiver(),
new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION));
SmsReceiver.onReceive(Context context, Intent intent)
永远不会被调用.
通知
- 设备API级别低于23 ,因此它不是运行时请求权限问题
- 尝试
IntentFilter.setPriority(1000)
没有成功. -
registerReceiver
返回空
- Device API Level is LOWER than 23 so it's not runtime request permission problem
- tried
IntentFilter.setPriority(1000)
with no success. registerReceiver
returns null
我该如何解决?
推荐答案
我该如何解决?
How can i fix that ?
首先使用正确的Intent
操作.
有两个与短信发送相关的操作字符串.适用于任何应用程序的—以及<intent-filter>
—中使用的内容. 是SMS_RECEIVED_ACTION
.什么仅适用于用户选择的SMS客户端—以及您要与IntentFilter
—一起使用的内容是SMS_DELIVER_ACTION
.这些不一样.
There are two action strings related to SMS delivery. What works for any app — and what you are using in the <intent-filter>
— is 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
. These are not the same.
这篇关于SMS_RECEIVED的动态广播注册不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!