4

The following is the code I'm using for starting my Application when device is turned on.

public class BootReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("BootReceiver","intent received");

        Intent myIntent = new Intent(context, ACT_Home.class);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(myIntent);
    }

}

and in the Manifest (as <Application> child):

<receiver android:name="host.alarmmanager.BootReceiver">
   <intent-filter >
      <action android:name="android.intent.action.BOOT_COMPLETED"/>
   </intent-filter>
</receiver>

The permissions inside the Manifest are the following:

<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

This works fine on Android 3.2.2, but if I try the same application on Android 4.0.3 the broadcast receiver does not receive anything. Also the first line inside the onReceive method is not execeuted. Why this happens?

GVillani82
  • 17,196
  • 30
  • 105
  • 172
  • 1
    [Did you start your app at least once manually?](http://stackoverflow.com/questions/9952562/broadcast-receiver-not-working-in-ics-if-the-app-is-not-started-atleast-once) – Selvin Sep 18 '13 at 09:30

3 Answers3

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

This you should use in android manifest

Lebedevsd
  • 950
  • 5
  • 12
2

Try this, although your code seems fine! The following is working for me.

    <!-- Receivers -->
    <receiver android:enabled="true" android:name="host.alarmmanager.BootReceiver"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103
1

Make sure you are not restarting your phone by selecting restart option from the power menu.

Android bizarrely has 2 different permissions.

1.Reboot

2.On boot complete

So, first power off your phone and then after few seconds power on it again!

Hope it helps! (Y)

Community
  • 1
  • 1