I using below code to insert new sms in inbox, but when i click on button, program give force close, what is the problem ?
Thanks
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button BTN = (Button) findViewById(R.id.button1);
BTN.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ContentValues values = new ContentValues();
values.put("address", "9878782944");
values.put("body", "foo bar");
values.put("date", "1322039220502");
values.put("read", "1");
getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
}
});
}
give this error :
FATAL EXCEPTION: main
java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.MmsSmsProvider uri content://mms-sms/threadID?recipient=9878782944 from pid=337, uid=10038 requires android.permission.READ_SMS
at android.os.Parcel.readException(Parcel.java:1247)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:408)
at android.content.ContentResolver.insert(ContentResolver.java:587)
at ir.fadesign.sms.Main$1.onClick(Main.java:25)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Based on your stack trace you need to add the “android.permission.READ_SMS” permission to your AndroidManifest.xml.
Add the line:
to your AndroidMainfest.xml file.
http://developer.android.com/guide/topics/security/security.html#permissions
SIDE NOTE:
It appears you’re trying to do some stuff with SMS. You may need additional permissions depending on what your end goal is.
Go here: http://developer.android.com/reference/android/Manifest.permission.html
And take a look at other SMS permissions:
READ_SMS,
WRITE_SMS,
SEND_SMS,
RECEIVE_SMS,
etc.