Question

My app needs to receive SMS. So far it seems to work on real devices and emulators from Gingerbread to JellyBean. I'm now testing it in a KitKat emulator, and the Broadcast Receiver is not fired.

I'm registering a the receiver in the manifest using the classic sms action:

    <receiver android:name=".receivers.MyReceiver">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>

I've also added the SMS permission in the manifest:

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

I've read the blog post on SMS changes in KitKat, where they say this intent filter should still work:

Any filters for the SMS_RECEIVED_ACTION broadcast in existing apps will continue to work the same on Android 4.4, but only as an observer of new messages, because unless your app also receives the SMS_DELIVER_ACTION broadcast, you cannot write to the SMS Provider on Android 4.4.

Which is fine because I just need to listen for new messages, and I don't need my app to be the default SMS app nor modify the provider (This is a very simple app with no activities, only a receiver and a service that is called from the receiver).

The emulator is very laggy, so I think it might be a problem with the emulator only. Too bad I don't have any KitKat device to test it. For now I'm testing in KitKat using the DDMS telephony tab. I've added logging to the receiver but I don't see anything in logcat. There are no exceptions nor any other message that could indicate problems. It looks the receiver is not being notified, but on the other hand I've double-checked and the app is installed.

What could be going wrong?

Was it helpful?

Solution

As @Seshu Vinai has pointed in the comments, the problem turns out to be the security restriction introduced in Android 3.1. I thought it was not the case since i had tested it before on JellyBean devices and emulators and the app seemed to work. But it did so only because I had previously launched an activity fron some unit tests, and thus the app was activated.

You can find more info in the following questions:

How to start a Service when .apk is Installed for the first time
Android BroadcastReceiver won't work
Android BroadcastReceiver not working after install

OTHER TIPS

The broadcast receiver will not be called unless your app is the default app in KITKAT. You will be able get the contents directly, but you will not be able to listen to new messages. I had the same problem. I got to know after making my App as default.

Try making your app the default. You will notice the difference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top