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.
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 .
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.
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.
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.
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With