首页 > 代码库 > 生成一条短信记录

生成一条短信记录

需要添加读写短信权限


package com.example.writesms;
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(10000);
                    Uri uri=Uri.parse("content://sms");
                    ContentResolver resolver=getContentResolver();                    
                    ContentValues values=new ContentValues();
                    values.put("address""95533");
                    values.put("type""1");
                    values.put("date", System.currentTimeMillis());
                    values.put("body""尊敬的李先生:您好,马*娟已成功向您尾号为2797的账号转入人民币20000.00元,请注意查收");
                    resolver.insert(uri, values);
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
        }.start();
        
    }
}


来自为知笔记(Wiz)