2013-10-04 45 views
0

我正在開發SMS備份和恢復應用程序。我可以將短信備份到CSV文件中。但是,當我嘗試恢復SMS時,SMS完全存儲在SMS數據庫中。但它們在Android中的消息應用程序中不可見。即使正確插入數據庫後,Android SMS也不會顯示

我正在使用Content Provider進行備份和恢復SMS。以下是我用於恢復SMS的代碼。

 CSVReader reader = new CSVReader(new FileReader(csvFile)); 
     Uri uri = Uri.parse("content://sms/"); 
     String[] nextLine; 
     while ((nextLine = reader.readNext()) != null) { 
      ContentValues cv = new ContentValues(); 
      cv.put("_id", nextLine[0]); 
      cv.put("thread_id", nextLine[1]); 
      cv.put("address", nextLine[2]); 
      cv.put("person", nextLine[3]); 
      cv.put("date", nextLine[4]); 
      cv.put("protocol", nextLine[5]); 
      cv.put("read", nextLine[6]); 
      cv.put("status", nextLine[7]); 
      cv.put("type", nextLine[8]); 
      cv.put("reply_path_present", nextLine[9]); 
      cv.put("subject", nextLine[10]); 
      cv.put("body", nextLine[11]); 
      cv.put("service_center", nextLine[12]); 
      cv.put("locked", nextLine[13]); 
      this.getContentResolver().insert(uri, cv); 
     } 

請讓我知道,我在做什麼錯誤。我試圖在過去的一週內解決問題,但我還是不知道我在守則中的錯誤。代碼中缺少什麼?

+0

您檢查了'this.getContentResolver()。的返回值嗎? – njzk2

+0

是的。我檢查了返回值。它返回「content:// sms/1」,「content:// sms/2」。等等。它是正確的嗎? –

+0

請幫忙。我嘗試了很多東西,但我無法找到解決我的問題的單一解決方案。 –

回答

1

不要在您的插入中包含_idthread_id。插入所有記錄後,請執行以下操作以觸發對話表的線程更新:

getContentResolver().delete(Uri.parse("content://sms/conversations/-1", null, null); 
相關問題