停止短信传播短信

2023-09-05 02:56:07 作者:老顽童!

我想不会在接收到这样的宣传短信

 公共类SMSReceiver扩展的BroadcastReceiver {
@覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        abortBroadcast();
        setResultData(空);
    }
}
 

AndroidManifest.xml中

 <接收机器人:名称=机器人:启用=真正的机器人SMSReceiver。优先=100>
          <意向滤光器>
            <作用机器人:名称=android.provider.Telephony.SMS_RECEIVED/>
          &所述; /意图滤光器>
        < /接收器>
 

而这是行不通的。我一直在寻找的天修复了。任何帮助高度AP preciated。

感谢

解决方案 张艺谋在线 打假

您需要设置安卓优先属性上的<意向 - 筛选> ,而不是<接收器GT;

例如

 <意图过滤器的Andr​​oid版本:优先=9999>
 

  

使用该属性只有当你真正需要施加一个特定的顺序   其中,广播接收,或者需要强制的Andr​​oid到   preFER比别人一个活动。该值必须是一个整数,如   100。数值越大,有更高的优先级。 (该命令只适用   为同步消息;它忽略异步消息。)

http://developer.android.com/guide/主题/清单/意图过滤element.html

I am trying to not to propagate an sms upon receiving like this

public class SMSReceiver extends BroadcastReceiver {
@Override
    public void onReceive(Context context, Intent intent) {
        abortBroadcast();
        setResultData(null);
    }
}

AndroidManifest.xml

<receiver android:name=".SMSReceiver" android:enabled="true" android:priority = "100" >
          <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
          </intent-filter>
        </receiver>

but this is not working. I have been looking for a fix for days now. any help is highly appreciated.

Thanks

解决方案

You need to set the android:priority attribute on the <intent-filter>, not the <receiver>.

e.g

<intent-filter android:priority="9999" >

Use this attribute only if you really need to impose a specific order in which the broadcasts are received, or want to force Android to prefer one activity over others. The value must be an integer, such as "100". Higher numbers have a higher priority. (The order applies only to synchronous messages; it's ignored for asynchronous messages.)

http://developer.android.com/guide/topics/manifest/intent-filter-element.html