android - 如何以编程方式增加 IntentFilter 的优先级

标签 android sms broadcastreceiver intentfilter notificationmanager

这就是我将我的应用程序 Intent 过滤器的优先级设置为最高的方式。在收到 Intent Extras 后我中止了广播,但 native 应用程序仍在接收短信并且通知栏仍在显示最烦人的消息内容因为我不希望它显示邮件正文。有什么我想念的吗??

<receiver android:name=".MySmsReceiver" > 
<intent-filter> 
        <action android:name="android.provider.Telephony.SMS_RECEIVED"
            android:priority="999"
             /> 
</intent-filter> 
</receiver>

这是我的接收者的onReceive()方法

public void onReceive(final Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    abortBroadcast();
             ....
 }

最佳答案

尝试以这种方式声明您的接收者:

<receiver android:name=".MySmsReceiver">
    <intent-filter android:priority="999">
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>

代替:

<receiver android:name=".MySmsReceiver" > 
<intent-filter> 
        <action android:name="android.provider.Telephony.SMS_RECEIVED"
            android:priority="999"
             /> 
</intent-filter> 
</receiver>

在中止广播之前,请尝试检查以下条件:

编辑:

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(SMS_RECEIVED)) {
        Bundle extras = intent.getExtras();
        if(extras != null)
          // doBroadcast();
        else
           abortBroadcast();
    }
}

希望对你有帮助。

谢谢。

关于android - 如何以编程方式增加 IntentFilter 的优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13927977/

相关文章:

android - 错误 :(41, 0) 提供的字符串模块符号 '0.12.2' 无效

android - 将 base64 字符串发送到服务器大小不正确

sms - 什么是短信网关

iOS:检测传入的短信

android - Activity 泄露了 IntentReceiver

Android:如何使用Retrofit获取 session ID?

android - android 是否加密通过 HttpConnection Post 或类似 Retrofit 的库发送的 https header ?

android - 如何让我的应用程序响应来自特定号码的短信

android - 来自广播接收者的通知

android - 结合 localbroadcastmanager sendorderedbroadcast 发送广播