BroadcastReceiver + SMS_RECEIVED

Viewed 56373

I'd like my app to catch incoming SMS messages. There are a few examples of this around. Looks like we just need to do this:

// AndroidManifest.xml
<receiver android:name=".SMSReceiver"> 
  <intent-filter> 
    <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
  </intent-filter> 
</receiver>        

// SMSReceiver.java
public class SMSReceiver extends BroadcastReceiver 
{ 
    @Override 
    public void onReceive(Context context, Intent intent) { 
        Log.i(TAG, "SMS received.");
        ....
    }
}

is this correct? I'm sending my phone some sms messages, but the log statement never gets printed. I do have some other SMS applications installed on the phone, which display a popup when the sms is received - are they somehow blocking the intent from getting passed down to my app, they are just consuming it completely?

Thanks

7 Answers

Did you try with the emulator ?

After deploying your application in the emulator, you can send events like SMS via the DDMS or via the command line by connecting with telnet :

telnet localhost <port_emulator>
send sms <incoming_tel_number> <sms_content>

port_emulator is usually 5554

Android Messenger (the SMS client) has a "Chat" feature which transmits messages over WiFi instead of SMS.

If the person you are testing with uses Messenger as well, you'll need to disable this feature on one or both of your devices otherwise there is no SMS message actually being received:

To turn chat features off:

  1. Open Messages Messages Logo Round.
  2. Tap More More and then Settings.
  3. Tap Advanced and then Chat features.
  4. Turn Enable chat features on or off.

https://support.google.com/messages/answer/7189714?hl=en

Related