简体   繁体   English

SMS_RECEIVED的动态广播注册不起作用

[英]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 注意

  • Device API Level is LOWER than 23 so it's not runtime request permission problem 设备API级别低于23,因此不是运行时请求权限问题
  • tried 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 IntentFilteris SMS_DELIVER_ACTION . SMS_DELIVER_ACTION只对用户选择的SMS客户端有效,而您要与IntentFilter一起使用。 These are not the same. 这些不一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM