短信恢复实现

1 篇文章 0 订阅
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;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值