0

I am creating an application that will send/receive messages to/from a certain gateway number. I don't want the messages that are sent to this particular number to be stored in the inbox of my device.

The code I am using to send the SMS is:

protected void sendMessage(String strMessage) {
    try {
        SmsManager smsMan = SmsManager.getDefault();
        smsMan.sendTextMessage(gatewayNumber, null, strMessage, null, null);

        Toast.makeText(getApplicationContext(),
                "SMS was sent successfully!",
                Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(),
                "SMS was not sent, please contact developer!",
                Toast.LENGTH_LONG).show();
    }
}

I have managed to tackle the problem of storing incoming messages by using the abortBroadcast(); function. (I realize this doesn't work above KitKat, and I'm fine with it).

But the messages that are sent from the application are being stored in the inbox too (only on KitKat), and that bothers me. Any solutions?

Amruth Pillai
  • 1,539
  • 2
  • 13
  • 28
  • try to abort broadcast and set the biggest priority on your Broadcast receiver – Gaskoin Feb 19 '15 at 15:51
  • @Gaskoin I am not inquiring about incoming messages getting stored, I want the outgoing messages to be intercepted. – Amruth Pillai Feb 19 '15 at 15:52
  • so you are basically trying to "tweak" behavior of native SMS app (another app, not your's)..how about creating an alternative SMS app and add that feature into it? If user like your SMS App, they will choose it as default...this is just a suggestion and also a hint too! – AADProgramming Feb 19 '15 at 16:38
  • @MeTechnical I don't want to take attention away from the default messaging app (at least for the sake of other SMSes that may be received). – Amruth Pillai Feb 19 '15 at 17:12
  • 1
    As you've seen, in KitKat (and above), any non-default SMS app that sends messages with SmsManager will have them automatically written to the Provider by the system. There's really no way to prevent this in a stock ROM. However, [my answer here](http://stackoverflow.com/a/27709655/2850651) demonstrates how to give a non-default app write access to the Provider in KitKat, which you could use to delete the messages immediately after being sent. You would also be able to delete the incoming messages meant for your app, as well. – Mike M. Feb 19 '15 at 20:53

0 Answers0