手机短信的操作

代码测试,插入短信,删除短信


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





原文链接: 手机短信的操作 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-138.html )

发表评论

0则评论给“手机短信的操作”