Android 如何通过编程增加IntentFilter的优先级
这就是我设置应用程序意图过滤器最高优先级的方式。在收到意图额外信息后,我中止广播,但本机应用程序仍在接收短信,通知栏仍在显示最烦人的消息内容,因为我不希望它显示消息正文。有什么我遗漏的吗Android 如何通过编程增加IntentFilter的优先级,android,sms,broadcastreceiver,intentfilter,notificationmanager,Android,Sms,Broadcastreceiver,Intentfilter,Notificationmanager,这就是我设置应用程序意图过滤器最高优先级的方式。在收到意图额外信息后,我中止广播,但本机应用程序仍在接收短信,通知栏仍在显示最烦人的消息内容,因为我不希望它显示消息正文。有什么我遗漏的吗 <receiver android:name=".MySmsReceiver" > <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED"
<receiver android:name=".MySmsReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"
android:priority="999"
/>
</intent-filter>
</receiver>
请尝试以以下方式声明您的收件人:
<receiver android:name=".MySmsReceiver">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
希望对你有帮助
谢谢。您可以使用上述条件
如果(intent.getAction().equals(SMS_RECEIVED))
这将仅侦听名为SMS_RECEIVED
的指定接收器。我只想从intent检索数据,然后中止广播..但是我现在使用这个条件所做的,在我中止广播之前,本机应用程序也获得了目的,notificationbar
将再次显示内容。orderbroadcast
是否有我需要处理的时间间隔???@anelasafdar查看我发布的编辑解决方案。希望能解决您的问题。如果extras不为null(大多数情况下为null),则使用此条件,您不会中止广播。因此本机应用程序将接收消息。如果我错了,请更正我。感谢您可以使用相同的条件并执行abortBroadcast()
当extras not null时,表示您获得了具有意图的extras
。
<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();
}
}