刚学习android,在使用内容提供者进行短信插入的时候总是不成功,直接上代码,请各路大神指点一二
public void click(View view) {
ContentResolver resolver = getContentResolver();
Uri uri = Uri.parse("content://sms/");
ContentValues values = new ContentValues();
values.put("address", "123456");
values.put("type", "1");
values.put("date", System.currentTimeMillis() + "");
values.put("body", "this is a mock message");
resolver.insert(uri, values);
}
在AndroidManifest.xml里面已经加上了访问sms权限
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
有关系的,android为了防止第三方软件拦截短信和乱写入短信记录,在4.4之后,设置了只有默认的短信应用才会有权限操作短信数据库,具体查看http://developer.android.com/about/versions/android-4.4.html#SMS
下面是正确的写法
ContentValues my_values = new ContentValues();
values.put("address", "+923359110795");//sender name
values.put("body", "this is my text");
getContentResolver().insert(Uri.parse("content://sms/inbox"), my_values);
推荐这个博客文章,已解决我的问题,http://www.cnblogs.com/tt2015...