代码测试,插入短信,删除短信
package com.gyarmy.insertsms; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.ContentResolver; import android.content.ContentValues; import android.view.Menu; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void add(View v){ ContentResolver resolver = getContentResolver(); Uri uri = Uri.parse("content://sms"); ContentValues values = new ContentValues(); values.put("address", "110"); values.put("date", System.currentTimeMillis()); values.put("type", "1"); values.put("body", "请尽快归案,否则准予枪毙"); resolver.insert(uri, values); } public void delete(View v){ ContentResolver resolver = getContentResolver(); Uri uri = Uri.parse("content://sms"); resolver.delete(uri, "address = ?", new String[]{"1 008-6"}); } }
注意权限
READ_SMS
WRITE_SMS
0则评论给“手机短信的操作”