我想以编程方式从我的Android设备中删除1条短信。这是我目前正在使用的代码。
private void DeleteSMS(int SmsId){
Cursor c = getContentResolver().query(Uri.parse("content://sms/"),new String[] {"_id", "thread_id", "address", "body" }, null, null, null);
while (c.moveToNext()) {
try {
int pid = Integer.valueOf(c.getString(0));; // Get id;
String smsMessage = c.getString(3);
if (pid == SmsId)
{
String uri = "content://sms/"+pid;
int rows = getContentResolver().delete(Uri.parse(uri), null, null);
Toast.makeText(context, rows+" Message Deleted", Toast.LENGTH_LONG).show();
break;
}
} catch (Exception e) {
Log.v("exception","occurred");
}
}
}
使用getContentResolver().delete
执行delete语句后,它将返回受影响的行为0。
答案 0 :(得分:1)
请检查此答案https://stackoverflow.com/a/8851644/3020568
您的应用应配置为默认短信应用,以处理短信 - 高于4.4
检查
http://android-developers.blogspot.in/2013/10/getting-your-sms-apps-ready-for-kitkat.html