Reputation: 1033
Good day,
I am creating an app based on this.
BroadcastReceiver and alarmManager Android
it is running smoothly,
then I try to make it run even the client boot its phone by adding this.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".MyBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
the problem is, broadcastreceiver is lost after reboot.
My BroadcastReceiver looks like this
public class MyBroadcastReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Toast.makeText(context, "Don't panik but your time is up!!!!.",
Toast.LENGTH_LONG).show();
// Vibrate the mobile phone
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
}
}
}
This is already fix. Thanks. (for future reference) :)
Upvotes: 0
Views: 65
Reputation: 1587
Try to update to the following.
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
//Do your stuffs here
}
}
Upvotes: 1