I have specified a receiver in the manifest like so ..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.MyProject"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher" android:enabled="true">
<service android:name="MyService"
android:exported="true"
android:process=":different"
android:enabled="true">
<intent-filter>
<action android:name="com.me.MyService">
</action>
</intent-filter>
</service>
<receiver android:exported="true"
android:name="MySMSBroadcastReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
If I test this on an Android Froyo device (emulator or real) this works as I expect. The MySMSBroadcastReceiver.onReceive(...) is being called when the device receives an SMS.
However if I install this on a 4.0 or 4.1 device (either emulator or a real device) nothing happens on an incoming message. No errors, no nothing. I also changed the properties for the project to target a 4.0 or 4.1 device specifically and re-installed it but that makes no difference.
Currently there is no way to check if a receiver is registered using the receiver reference. You have to unregister the receiver and catch the IllegalArgumentException that is thrown if it's not registered.
A broadcast receiver (receiver) is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens.
There are mainly two types of Broadcast Receivers: Static Broadcast Receivers: These types of Receivers are declared in the manifest file and works even if the app is closed. Dynamic Broadcast Receivers: These types of receivers work only if the app is active or minimized.
When a broadcast message arrives for the receiver, Android calls its onReceive() method and passes it the Intent object containing the message. The broadcast receiver is considered to be active only while it is executing this method. When onReceive() returns, it is inactive.
After your application is installed, the user need to launch an activity of yours manually before any of your BroadcastReceivers will have an effect, as of Android 3.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With