Reputation: 3858
I'm trying to implement a broadcast receiver that catch the boot complete event.
I put the permission in the manifet
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
I put the intent filter after the receiver tag in the manifest (the class file is in the receivers package)
<receiver android:name=".receivers.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
</receiver>
and finally I declared the receiver class. The class should load some data from the database and set an alarm. However to check if it works I've put a Toast but it's not displayed and a vibra.
public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent callingIntent) {
Vibrator vibrator=(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(5000);
Toast.makeText(context, "BOOT RECEIVED", Toast.LENGTH_LONG).show();
}
}
Anyone knows why please?
Upvotes: 0
Views: 915
Reputation: 1139
All just installed applications gets into the stopped state (the actual file is /data/system/packages-stopped.xml)
Starting from Android 3.1, the system's package manager keeps track of applications that are in a stopped state. See this link: android 3.1 launch control.
Intent with action android.intent.action.BOOT_COMPLETED
has a FLAG_EXCLUDE_STOPPED_PACKAGES
extra flag. It means that all stopped applications will not receive the BOOT_COMPLETED
events.
To get your application out of the stopped state, start it manually just after installation. Then you can do a reboot and will see the expected Toast.
Upvotes: 1