3

Before Android KitKat, it was possible to send SMS messages without them being stored in the sent folder of the installed messaging apps on the device, using this method:

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phonenumber, null, message, null, null);

But how is it done post-KitKat? Do you have to delete the messages that are sent out by your app? And if so, how is it done correctly?

Armadillo
  • 457
  • 1
  • 9
  • 17

1 Answers1

0

Starting with KitKat, any app with the SEND_SMS permission is able to send messages with the standard SmsManager methods, and the system will handle writing the messages to the Provider automatically. As the default app is the only one with write access to the Provider, it is the only one that can delete messages, so any non-default app won't be able to delete those messages written automatically.* If you don't want them to be written, your app should be set as the default SMS app. The default app is responsible for writing its own outgoing messages, and it can opt not to do so.


* A possible workaround for the write access restriction in Android 4.4 (KitKat) can be found in the answer here.

Community
  • 1
  • 1
Mike M.
  • 38,532
  • 8
  • 99
  • 95
  • In fact, here is the identical question with your accepted answer :) http://stackoverflow.com/questions/20158998/marking-deleting-message-doesnot-work-in-android-kitkat – GoRoS Aug 11 '14 at 16:12
  • @GoRoS Not exactly identical, but it explains why attempting to delete from a non-default app won't work. – Mike M. Aug 11 '14 at 16:15
  • Ah, I understand. So there is no possible way for an app that's not the default SMS app to delete sms messages (write access). – Armadillo Aug 11 '14 at 16:25
  • How about the app the sends sms in the background? Is it possible to set it as default sms app? – mboy Sep 19 '14 at 02:59
  • I have already read that post and tried but I still can't get my app as default.. My app is just an intent service(no activity) that sends and delete specific messages. I don't think it would be nice for an app to become a default messaging app while that app has no activity because it is just intent service.. :) I'm confused with this update.. – mboy Sep 19 '14 at 03:18
  • @mboy Nope, that's not going to be able to be a default SMS app. There can be only one default at a time, and the one selected as such is responsible for many things. Also, when an app is not the default, it's expected to adjust its behavior accordingly, which means even if you have another fully functional SMS app installed, it's not going to be able to substitute for the default for actions it (the default) is not handling. – Mike M. Sep 19 '14 at 03:23
  • So are you saying that there is no way for my app to function as it is before Kitkat? My app is not actually a messaging app it is just use to automate the sending and deleting sms but the deleting functionality doesn't work anymore because as we all knew only default app has the privilege to do the that. I'm digging Google until now but I can't find relevant info for my problem.. :) I'm planning now to downgrade this to JB and I'm sure it will solve the problem automatically.. hehe – mboy Sep 19 '14 at 03:29
  • Thanks @MikeM I'm now going to buy old phones or downgrade this phone.. :) – mboy Sep 19 '14 at 03:35
  • @mboy Yep. (Sorry. I was editing my last comment and accidentally deleted it.) If the app is just for personal use, then I would mention that it is technically possible to get it working like it did in JB, but unless you have another SMS app installed that will still send SMS, handle MMS, provide Notifications, etc., you're gonna lose a lot of functionality. There might be some apps that will still do as much as they can when not the default, but I don't know of any. All the ones I've used won't even let you send a regular text message if they're not the default. – Mike M. Sep 19 '14 at 03:41
  • Yes. it is just for personal use. This phone is specifically use for this purpose so I don't care what other features to lose as long as my app is able to send/delete sms.. :) I just can't find any info or even from Google Developers website how to do this in an intent service to have default messaging app like permission. – mboy Sep 19 '14 at 03:49
  • @mboy Well, the manifest in that link is where you start. Just make sure to add the correct permissions (I don't think they're listed there), and your app should appear in the default list. Depending on how you install it, though, you might need to have some minimal Activity to open once before it'll work, even if you never use the Activity again. – Mike M. Sep 19 '14 at 04:10
  • 1
    @MikeM. that is what I did right now.. I created activity of for my app and defined that permissions in the manifest and it is now showing in the default list. I will update you once I confirmed everything is working.. :) – mboy Sep 19 '14 at 04:16
  • @MikeM. can u tell me if i just want to delete sms from sent items may i still need to make my app as default sms app ? how can i make my app as default sms app – Erum Feb 11 '15 at 06:44
  • @ErumHannan Short answer: yes, you're supposed to. To make your app eligible to be default, please check the following: [Getting Your SMS Apps Ready for KitKat](http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html?m=1). However, if your app is meant to support a version no higher than KitKat, I've a workaround for that in [my answer here](http://stackoverflow.com/a/27709655/2850651). Unfortunately, it apparently doesn't work as-is for Lollipop (API 21), and I've yet to delve into that source code to determine why. If/when I do, I'll let you know. – Mike M. Feb 14 '15 at 01:44
  • @MikeM. i just want to delete failure messages from device as i have successfully deleted all messages if i want to delete messages from device then may i still need to make my app as default sms app ? – Erum Feb 16 '15 at 04:17