停止短信传播

kak*_*ppa 3 android

我试图在收到这样的短信时不传播短信

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

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>
Run Code Online (Sandbox Code Playgroud)

但这不起作用.我一直在寻找解决方案.任何帮助都非常感谢.

谢谢

Chr*_*Orr 6

你需要设置android:priority属性<intent-filter>,而不是<receiver>.

例如

<intent-filter android:priority="9999" >
Run Code Online (Sandbox Code Playgroud)

仅当您确实需要强制接收广播的特定订单,或者希望强制Android更喜欢某个活动而不是其他活动时,才使用此属性.该值必须是整数,例如"100".数字越大,优先级越高.(该命令仅适用于同步消息;异步消息会忽略它.)

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