Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用BroadCastReceiver删除短信-Android_Android - Fatal编程技术网

使用BroadCastReceiver删除短信-Android

使用BroadCastReceiver删除短信-Android,android,Android,我有接收短信的广播接收器类,但我不知道如何在到达收件箱和通知之前删除收到的短信 public void onReceive(Context context, Intent intent) { Bundle pudsBundle = intent.getExtras(); Object[] pdus = (Object[]) pudsBundle.get("pdus"); SmsMessage messages =SmsMessa

我有接收短信的广播接收器类,但我不知道如何在到达收件箱和通知之前删除收到的短信

public void onReceive(Context context, Intent intent) {     
        Bundle pudsBundle = intent.getExtras();     
        Object[] pdus = (Object[]) pudsBundle.get("pdus");
        SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);        
        Log.i(TAG,  messages.getMessageBody());
}

在意图过滤器中,您应该将优先级设置为高于系统SMS应用程序



这将很好。

介意显示广播接收器的代码吗?与此相关,这不会停止所有广播吗?他应该有if-intent.action().equals(“WhateverTheActionIsCalled”)阿伦:你安装了自定义短信应用程序吗?如果该应用程序的优先级高于您的意图过滤器,那么他们将首先接收它。尝试增加优先级。另外,如果您没有从
onreceive()
快速返回,它可能会继续到下一个广播接收器。Android priority不适用于我这里是我在mani fest文件中使用的代码。。使用abortBroadcast();?是否需要任何权限@Sando:尝试使用android:priority=“9999”
   public void onReceive(Context context, Intent intent) {
     //... 
     abortBroadcast();
   }
<receiver android:name=".SMSReceiver"
         android:permission="android.permission.BROADCAST_SMS"> 
        <intent-filter android:priority="999" > 
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
</receiver>
  public void onReceive(Context context, Intent intent) {
     //... 
     abortBroadcast();
   }