2014-06-28 3 views
0

J'ai un code pour supprimer les messages SMS dans la boîte d'envoi avec Android, mais pourquoi les messages SMS ne sont pas supprimés ..SMS pas supprimé

delete.setOnClickListener(new OnClickListener() { 
     @Override 
public void onClick(View v) { 
Dialogs.showConfirmation(LookSms.this,"Are you sure?", 
new DialogInterface.OnClickListener() { 

public void onClick(DialogInterface dialog,int which) { 
Intent i = getIntent(); 
String id_delete_sms = i.getStringExtra("protocol"); 
String id_delete_thread = i.getStringExtra("address"); 

// hapus pesan 
Uri deleteUri = Uri.parse("content://sms"); 

getContentResolver().delete(deleteUri,"thread_id=? and protocol=?", 
new String[] {String.valueOf(id_delete_thread),String.valueOf(id_delete_sms) }); 

finish(); 
Toast.makeText(LookSms.this,"SMS deleted", Toast.LENGTH_SHORT).show(); 
} 
      }); 

Répondre

0

hey utiliser ce code pour supprimer customize sms 1. Par date 2 Par le numéro 3. Par corps

try { 
     Uri uriSms = Uri.parse("content://sms/inbox"); 
     Cursor c = context.getContentResolver().query(
       uriSms, 
       new String[] { "_id", "thread_id", "address", "person", 
         "date", "body" }, "read=0", null, null); 

     if (c != null && c.moveToFirst()) { 
      do { 
       long id = c.getLong(0); 
       long threadId = c.getLong(1); 
       String address = c.getString(2); 
       String body = c.getString(5); 
       String date = c.getString(3); 
       Log.e("log>>>", 
         "0--->" + c.getString(0) + "1---->" + c.getString(1) 
           + "2---->" + c.getString(2) + "3--->" 
           + c.getString(3) + "4----->" + c.getString(4) 
           + "5---->" + c.getString(5)); 
       Log.e("log>>>", "date" + c.getString(0)); 

       ContentValues values = new ContentValues(); 
       values.put("read", true); 
       getContentResolver().update(Uri.parse("content://sms/"), 
         values, "_id=" + id, null); 

       if (message.equals(body) && address.equals(number)) { 
        // mLogger.logInfo("Deleting SMS with id: " + threadId); 
        context.getContentResolver().delete(
          Uri.parse("content://sms/" + id), "date=?", 
          new String[] { c.getString(4) }); 
        Log.e("log>>>", "Delete success........."); 
       } 
      } while (c.moveToNext()); 
     } 
    } catch (Exception e) { 
     Log.e("log>>>", e.toString()); 
    }