2011-05-11 49 views

回答

-1

我正在尋找同樣的事情。

我使用這個代碼數量,檢查它的工作原理:

public void deleteOneSMS(int threadIdNo) { 

    try { 

    Uri uriSms = Uri.parse("content://sms/inbox"); 

    Cursor c = getContentResolver().query(uriSms,new String[] { "_id", "thread_id" }, null, null, null); 

    if (c != null && c.move(threadIdNo)) { 

     do { 

      long threadId = c.getLong(1); 

      count++; 

      //System.out.println("threadId:: "+threadId); 

      if (count == threadIdNo){ 

      getContentResolver().delete(
        Uri.parse("content://sms/conversations/" + threadId), 
        null, null); 

       } 

      } while (c.moveToNext()); 

     } 
    }catch (Exception e) { 

    // TODO: handle exception 

    System.out.println("Exception:: "+e); 

    } 
} 
-1

如果你想在一個時間,而不是所有的談話只刪除一個短信,那麼這個例子可以幫助你,我在這裏從收件箱中獲取最重要的短信並將其刪除,請記住,每個短信都有其線程和ID值,以區別於其他短信。

try 
     { 
     Uri uri = Uri.parse("content://sms/inbox");   
     Cursor c =v.getContext().getContentResolver().query(uri, null, null ,null,null); 
     String body = null; 
     String number = null;   
     if(c.moveToFirst()) 
     {} 
     } 
     catch(CursorIndexOutOfBoundsException ee) 
      { 
      Toast.makeText(v.getContext(), "Error :"+ ee.getMessage() ,Toast.LENGTH_LONG).show(); 
      } 
3

只需使用此代碼。

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); 
       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[] { <your date>}); 
        Log.e("log>>>", "Delete success........."); 
       } 
      } while (c.moveToNext()); 
     } 
    } catch (Exception e) { 
     Log.e("log>>>", e.toString()); 
    } 
相關問題