13

My questions specific only for Android 6 (starting from v23 of SDK). I need to get all SMS, even draft for future processing. Nothing special here, used the following peace of code:

context.getContentResolver().query(Uri.parse("content://sms/"),
new String[] {...}, null, null, null)

And this work perfect for Android 5, meaning that I get all SMS messages including draft. But at all devices with Android 6, I get only sent and received messages and NO DRAFT. Try to make my app default SMS before trying to query SMS – but no luck, at Android 6 i still cannot get draft messages. What the problem? I've already found some related posts SMS missing from content provider results on Android Marshmallow But this do not solve my issue at all.

Community
  • 1
  • 1
Aliaksei Lithium
  • 384
  • 1
  • 5
  • 13

3 Answers3

2

For Marshmallow you need to add run time permissions to read messages .

Check permission like this

int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_SMS);

If permission denied tha ask at run time like that

ActivityCompat.requestPermissions(this, new String[]{{Manifest.permission.READ_SMS}, PERMISSIONS_REQUEST_READMESSAGE);

to access draft this is URI for content provider.

Content provider for draft is

content://sms/draft

Note: dont forget to add permissions

<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
umair
  • 607
  • 4
  • 18
1

I believe what your looking for is found in this answer. It provides a list of URI's for accessing the different SMS boxes. The one specifically for the draft SMS messages is

content://sms/draft

Community
  • 1
  • 1
Jason Crosby
  • 3,533
  • 4
  • 28
  • 49
  • 2
    Thats not work. Prior Android 6 there is no problem to get draft sms directly `content://sms/draft` or even by `content://sms/`. But with Marshmallow, they are filtered out. – Aliaksei Lithium Jul 25 '16 at 20:03
1

Query on URI content://sms/draft will return only the draft messages that are stored in SMS provider.

Default android messaging application implementation stores the draft messages within the application and will not add the drafts to SMS provider.

Only the draft messages that are part of SMS provider (can added using SMSManager's hidden API addTextMessageDraft) will be returned as results when query on URI content://sms/draft is performed.

Suresh
  • 9,495
  • 14
  • 49
  • 63