SMS_RECEIVED的动态广播注册不起作用 [英] Dynamic broadcast registration for SMS_RECEIVED is not working

查看:574
本文介绍了SMS_RECEIVED的动态广播注册不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆