Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android <receiver> - BroadcastReceiver not called

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.

like image 559
Lieuwe Avatar asked Sep 05 '12 10:09

Lieuwe


People also ask

How do I check if BroadcastReceiver is registered?

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.

What is BroadcastReceiver Android?

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.

Which are the BroadcastReceiver are available in Android?

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.

What is the life cycle of BroadcastReceiver in Android?

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.


1 Answers

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.

like image 89
Piyush Agarwal Avatar answered Sep 22 '22 20:09

Piyush Agarwal