5

Recently a question here on SO ported this to my attention. Android doesn't have a public API for listening to incoming SMS. There used to be an action android.provider.Telephony.SMS_RECEIVED, but it has been removed from the official API and even if it still works, it's obviously not future-proof. I don't need this feature right now, but I may in the future, and I find it very strange it's not available because:

  1. Android has always encouraged the deep customization of every little part of the system (think of tha launcher, the dialer, the contact app)
  2. There are plenty of alternatives to the standard SMS app already in the Market (not to mention the vendors' ones)

Maybe I am missing something or maybe there's a technical reason - I admit not know how SMS works

Raffaele
  • 20,627
  • 6
  • 47
  • 86

1 Answers1

0

I think if you set up an IntentReceiver it should work just fine.

public class SMSListener extends IntentReceiver {

    @Override
    public void onReceiveIntent(Context context, Intent intent) {
        SmsMessage[] messages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
    ...
}

Make sure you also include the permission
<uses-permission android:name="android.permission.RECEIVE_SMS" /> in your AndroidManifest.

This is as much as I know about it, but maybe other links will help you.
Here's one

Here's another.

Also, although this is slightly off-topic from your question, I learned what I know about Android SMS from this site, so maybe you can pick something up from there too!

Good luck and I hope I helped!

Community
  • 1
  • 1
  • Maybe you didn't read my question carefully, but I'm interested in why this method is not in the official documentation/API. I already knew what you suggested, but it's not safe to use something removed from the vendor's public doc – Raffaele Feb 14 '12 at 11:26