【问题标题】:stop SMS propagation停止短信传播
【发布时间】:2011-02-07 09:14:23
【问题描述】:

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

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>

但这不起作用。几天来我一直在寻找解决方法。非常感谢任何帮助。

谢谢

【问题讨论】:

  • 您的意思是“这似乎工作”?
  • opps.. 已更正,谢谢

标签: android


【解决方案1】:

您需要在&lt;intent-filter&gt; 上设置android:priority 属性,而不是&lt;receiver&gt;

例如

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

仅当您确实需要强制执行特定顺序时才使用此属性 在其中接收到广播,或者想要强制 Android 喜欢一项活动胜过其他活动。该值必须是整数,例如 “100”。数字越大优先级越高。 (该命令仅适用于 同步消息;对于异步消息,它会被忽略。)

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

【讨论】:

  • 哎呀,感谢您的提示。我对android还是有点陌生​​。顺便说一句,它就像一个魅力。
【解决方案2】:

由于我无法对@Christopher Orr 的回答添加评论,因此必须指出,优先级必须在 [-1000, 1000] 之间。 9999太多了。

该值必须是整数,例如“100”。更高的数字有 更高的优先级。默认值为 0。该值必须更大 小于 -1000 且小于 1000。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 2023-01-23
    • 2021-03-25
    • 2021-09-15
    • 1970-01-01
    相关资源
    最近更新 更多