I have created a messaging app that can be set as the default SMS app in KitKat (Android 4.4). This app listens for and catches specific messages, then raises an event after receiving them. The problem is that messages I don't need to catch are not appearing in the native messaging app's inbox. How can I display those messages in the native messaging app on the device while having my app as the default?
Asked
Active
Viewed 679 times
1 Answers
1
When your app is the default SMS app, it is responsible for writing incoming messages to the Provider, as it is the only app with write access to it. The following is a very simple, minimal example, and assumes you have the following import:
import android.provider.Telephony.*;
And the example write method:
private void insertSms(String number, String message)
{
ContentValues smsValues = new ContentValues();
smsValues.put(Sms.ADDRESS, number);
smsValues.put(Sms.BODY, message);
smsValues.put(Sms.DATE, System.currentTimeMillis());
context.getContentResolver().insert(Sms.Inbox.CONTENT_URI, smsValues);
}

Mike M.
- 38,532
- 8
- 99
- 95
-
Yay!It works on kitkat! Thanks. But how can I alert the default notification sound on inbox except for the messages that I should catch/hide? – níkē Oct 09 '14 at 06:43
-
As the default, your app is responsible for handling everything that the native app would have. You'll have to create a Notification with the desired icons, text, sound, etc. There really isn't a way to pass it off to the native app, since it pretty much disables itself when it's not the default. – Mike M. Oct 09 '14 at 06:50
-
But my app's task should only listen and catch for certain messages encrypted in my application, it is not made to be a messaging app that manages incoming and outgoing messages like what native messaging does. Unfortunately, on kitkat I have to set my app as the default sms in order to abort certain messages. Any advice on what should I do?My only problem is that I can't use abortbroadcast() in kitkat. – níkē Oct 09 '14 at 07:02
-
It might be possible to use data SMS, as opposed to regular text SMS. I don't believe the native app would pay attention to those, so you could leave it as the default SMS and still retrieve messages meant just for your app, without having to abort anything. I've not tested that in KitKat, though, so I'm not certain. – Mike M. Oct 09 '14 at 07:14
-
I'm not much familiar with data SMS, I don't even know yet how would I practice that on real device and how would I set-up a port for that. If it won't be such a hassle, can you give me an idea about data SMS on real devices? – níkē Oct 09 '14 at 07:36
-
They're really simple, and very similar to regular SMS. You just have to specify a couple extra things in the `
` manifest element, use the `sendDataMessage()` method, and decode the message a little differently. I just tested on a 4.4 device, and it works beautifully. [Check this post](http://stackoverflow.com/questions/3757229/how-to-send-and-receive-data-sms-messages) for details. – Mike M. Oct 09 '14 at 07:51 -
Yes I've tried it now, but how would other devices send data sms to devices installed with my app? Err stackoverflow warns me to move this discussion into chat but I don't have enough reputation yet. Is there any other way to contact you? Sorry for bothering you though. – níkē Oct 09 '14 at 08:06
-
I guess I'm unclear on your setup. Is your app receiving messages from only other devices with your app sending? Or is your app just looking for messages that contain certain words, that any SMS app can send? (Don't worry about the chat thing. If a mod doesn't like it, they can move us there. Otherwise, we'll just clean up afterward.) – Mike M. Oct 09 '14 at 08:12
-
Yes, my app is just looking for messages that contains specific text that any other devices can send without having my app installed in their device. My app's task is just to catch and abort immediately the message that contains certain words. – níkē Oct 09 '14 at 08:19
-
Well, then you're kinda stuck. You'll have to use regular text SMS, but in order to hide messages on KitKat, your app has to be default. But, being default means your app has to take care of a bunch of stuff. There's no way around that. A lot of apps with SMS functionalities for older Android versions broke when KitKat happened, just because that's how Google decided to implement the SMS API when they made it public. – Mike M. Oct 09 '14 at 08:27