短信恢复的原理——使用内容提供者

    public class MainActivity extends Activity {


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void back(View view){
        ContentResolver resolver = getContentResolver();
        Uri uri = Uri.parse("content://sms");
        ContentValues values = new ContentValues();
        values.put("address", "110");
        values.put("body", "过来喝茶吧");
        values.put("date",System.currentTimeMillis());
        values.put("type", "1");//1是收短信,2是发短信
        values.put("read", "0");//0是未读,1是已读
        resolver.insert(uri, values);
        Toast.makeText(this, "还原成功", Toast.LENGTH_SHORT).show();
    }

}

你可能感兴趣的:(安卓开发之旅)