0

I'm using Android Marshmallow. I tried to save SMS in draft but it doesn't get saved. I used the following code:

ContentValues values = new ContentValues();
values.put("address", edphone_no.getText().toString());
values.put("body", edTextmsg.getText().toString());
values.put("date", String.valueOf(System.currentTimeMillis()));
values.put("type", "3");
values.put("thread_id", "0");
getContentResolver().insert(Uri.parse("content://sms/draft"), values);

In Manifest.xml permissions are declared:

<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />

Code for fetching draft SMS:

 Uri draftURI = Uri.parse("content://sms/draft");
 String[] reqCols = new String[] { "_id", "address", "body" };
 ContentResolver cr = getContentResolver();
 Cursor c = cr.query(draftURI, reqCols, null, null, null);
Cœur
  • 34,719
  • 24
  • 185
  • 251
Bhagyashri
  • 172
  • 14
  • How did you fetch the sms ? Was it correctly fetched ? – Shubham Apr 20 '18 at 10:17
  • @ Shubham Srivastava edited code for fetching draft sms – Bhagyashri Apr 20 '18 at 10:21
  • refer this link hear can define some sdk versions https://stackoverflow.com/questions/4592966/is-it-possible-to-save-sms-in-drafts-using-android-sdk?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Ali Apr 20 '18 at 10:21
  • Is your app the default messaging app? If not, you can't write to the SMS Provider. In fact, since Marshmallow, non-default apps can't even read anything except _sent_ and _inbox_ messages. – Mike M. Apr 20 '18 at 10:44
  • @ Mike M my messaging app is not a default app.But Im able to read draft mesages. – Bhagyashri Apr 20 '18 at 11:13
  • @Mohammad Ali yes i refered that link also .But it not worked – Bhagyashri Apr 20 '18 at 11:14
  • Yeah, sorry, I should've said "in a standard system". Apparently certain manufacturers still let non-defaults read everything. – Mike M. Apr 20 '18 at 11:18

0 Answers0