繁体   English   中英

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

[英]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)

注意

  • 设备API级别低于23,因此不是运行时请求权限问题
  • 尝试了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.

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