我想要在Android棒棒糖和棉花糖中以編程方式刪除特定聯繫人號碼的郵件。從收件箱中刪除郵件或在Android棒棒糖和棉花糖中以編程方式發送
我使用下面的代碼讀取和刪除的郵件......但是這個代碼不實際刪除郵件:
public List<Sms> getAllSms() {
try {
List<Sms> lstSms = new ArrayList<Sms>();
Sms objSms = new Sms();
Uri uriSms = Uri.parse("content://sms/");
Cursor c = getActivity().getContentResolver().query(uriSms, new String[]{"_id", "thread_id", "address", "person", "date", "body"}, null, null, null);
getActivity().startManagingCursor(c);
int totalSMS = c.getCount();
if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
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));
if (address.equals("1234567890")) {
// mLogger.logInfo("Deleting SMS with id: " + threadId);
getContext().getContentResolver().delete(
Uri.parse("content://sms/" + id), null, null);
Log.e("log>>>", "Delete success.........");
}
c.moveToNext();
}
} else {
throw new RuntimeException("You have no SMS ");
}
c.close();
return lstSms;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
清單權限:
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
請幫我向有關刪除消息。
OR
建議我的方式來做到以下幾點:
如果我在後臺兩個以上的Android版本發送短信編程那麼它不應該保存在發送文件夾或在裝置內的任何消息。