package com.example.zhuangbi;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(){
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// 1. 获取内容解析器
ContentResolver resolver = getContentResolver();
// 2. 指定uri
Uri uri = Uri.parse("content://sms/");
ContentValues values = new ContentValues();
values.put("address", "95555");
values.put("read", 0);
values.put("type", 1);
values.put("body", "您的尾号为1452卡已打入人民币¥100000000.00元 【招商银行】");
values.put("date", System.currentTimeMillis());
resolver.insert(uri, values);
};
}.start();
}
}
清单文件中加权限:
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />