Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.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
Android 如何从特定号码中删除所有当前和以前的邮件?_Android - Fatal编程技术网

Android 如何从特定号码中删除所有当前和以前的邮件?

Android 如何从特定号码中删除所有当前和以前的邮件?,android,Android,此代码仅删除最后一条消息表单的特定编号,而不是特定编号中的所有消息。如何删除所有邮件 如果在运行应用程序之前发送3条消息,则在收到新消息时运行应用程序将停止应用程序。若我手动删除收件箱中的所有信息,然后在启动应用程序后从特定号码发送短信,那个么它工作正常。所以,我应该如何修改这段代码来检查收件箱中以前的带有特定号码的邮件,并将其全部删除 public class SmsReceiver extends BroadcastReceiver { String specificPhoneNum

此代码仅删除最后一条消息表单的特定编号,而不是特定编号中的所有消息。如何删除所有邮件

如果在运行应用程序之前发送3条消息,则在收到新消息时运行应用程序将停止应用程序。若我手动删除收件箱中的所有信息,然后在启动应用程序后从特定号码发送短信,那个么它工作正常。所以,我应该如何修改这段代码来检查收件箱中以前的带有特定号码的邮件,并将其全部删除

public class SmsReceiver extends BroadcastReceiver {    
String specificPhoneNumber = "15555215554";

public void onReceive(Context context, Intent intent) {

    abortBroadcast();
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;
    String str = "";     
    if (bundle != null) { 
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                

            String phNum = msgs[i].getOriginatingAddress();  

            str += msgs[i].getMessageBody().toString();
            if (specificPhoneNumber.equals(phNum)){
                Uri uri = Uri.parse("content://sms/inbox");
                ContentResolver contentResolver = context.getContentResolver();
                String where = "address="+phNum;
                Cursor cursor = contentResolver.query(uri, new String[] { "_id", "thread_id"}, where, null,null);
                while (cursor.moveToNext()) {               
                long thread_id = cursor.getLong(1);
                    where = "thread_id="+thread_id;
                    Uri thread = Uri.parse("content://sms/inbox");
                    context.getContentResolver().delete(thread, where, null);

                }
                  Intent l = new Intent(context,AgAppMenu.class);
                  l.putExtra("msg",str);
                  l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(l);                   
        }}}
公共类SmsReceiver扩展了BroadcastReceiver{
字符串specificPhoneNumber=“15555215554”;
公共void onReceive(上下文、意图){
abortBroadcast();
//---获取传入的SMS消息---
Bundle=intent.getExtras();
SmsMessage[]msgs=null;
字符串str=“”;
如果(bundle!=null){
//---检索收到的SMS消息---
Object[]pdus=(Object[])bundle.get(“pdus”);
msgs=新SMS消息[PDU.length];

对于(int i=0;i您是否有写短信权限?是的,但此代码仅在应用程序运行后删除短信如果我在应用程序运行前发送了许多短信,则发送短信应用程序将在启动应用程序后关闭其nort删除短信,然后短信来自特定号码,然后将其删除