Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get draft SMS in Android 6 Marshmallow

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.

like image 203
Aliaksei Lithium Avatar asked Jul 13 '16 07:07

Aliaksei Lithium


People also ask

How do I find my draft text messages on my android?

From the Home screen, tap , and then find and tap Messages. Tap a draft message, and then edit the message. Tip: To see all draft messages in one place, tap , and then tap Filter > Drafts. Tap .

How do I find a text draft?

From the "All Messages" view, press the Menu button. A "Drafts" icon appears (a floppy disk icon) - press that, and it takes you to a view of all your drafts.

How do I open a draft message?

Open a draft message you never sent In the folder pane, click the Drafts folder, then double-click the message. If you want to delete a draft, right-click a message in the draft folder and select Delete.

What does it mean message in draft?

Your phone saves the message as a draft that will be waiting in your Text Messaging inbox when you're ready to finish and send it (or delete it). To find the draft, touch Messaging > Text Messaging.


2 Answers

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>
like image 142
umair Avatar answered Nov 02 '22 23:11

umair


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

like image 29
Jason Crosby Avatar answered Nov 03 '22 00:11

Jason Crosby