private void restoreSms(String where, String [] args) {
int id = 0;
if (args == null) {
where = where.replaceAll(" ", "");
id = Integer.parseInt(where.substring(where.indexOf("=") + 1, where.length()));
}
Cursor c = null;
String [] projection = new String[] {"address", "body", "date", "phone_id", "_id"};
String selection = null;
if (id == -1) {
c = query(SMS_BLOCK_FOLDER_CONTENT_URI, projection, null, null, null);
}
else if (id > 1 && args == null) {
c = query(SMS_BLOCK_FOLDER_CONTENT_URI, projection, "_id = " + id, null, null);
}
else if(id == 0 && args != null) {
selection = "_id = ?";
for (int i = 1; i < args.length; i++) {
selection += " or _id = ?";
}
c = query(SMS_BLOCK_FOLDER_CONTENT_URI, projection, selection, args, null);
}
if (c != null) {
Uri uri = null;
if (c.getCount() == 1) {
c.moveToFirst();
uri = addToInbox(c);
delete(SMS_BLOCK_FOLDER_CONTENT_URI, "_id = " + c.getInt(4), null);
}
else if (c.getCount() > 1) {
while (c.moveToNext()) {
uri = addToInbox(c);
}
if (id == -1) {
mOpenHelper.getWritableDatabase().execSQL("DELETE FROM " + SMS_BLOCK_FOLDER_CONTENT_URI);
}
else {
delete(SMS_BLOCK_FOLDER_CONTENT_URI, selection, args);
}
}
}
if (c != null) {
c.close();
}
}
private Uri addToInbox(Cursor c) {
int phoneid = 0;
if (DualMode.getPhoneId(c.getInt(3)) == 1) {
phoneid = 1;
}
ContentValues values = new ContentValues();
values.put("address", c.getString(0));
values.put("type", "1");
values.put("read", "0");
values.put("body", c.getString(1));
values.put("date", c.getLong(2));
values.put("phone_id", phoneid);
return MmsApp.getApplication().getApplicationContext().getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
}
调用
public void onClick(View v) {
int de = 0;
switch (v.getId()) {
case R.id.insert:
de = contentResolver.delete(Uri.parse(“content://com.android.mms.provider.LjtMmsProvider/block_sms_restore”), "_id = " + -1, null);
break;
case R.id.insert2:
de = contentResolver.delete(Uri.parse(“content://com.android.mms.provider.LjtMmsProvider/block_sms_restore”), "_id = " + 16, null);
break;
case R.id.insert3:
de = contentResolver.delete(Uri.parse(“content://com.android.mms.provider.LjtMmsProvider/block_sms_restore”), “_id = ?”, new String[] {“1”, “3”, “5”});
break;
}
}