Ajith K P Ajith K P - 2 months ago 20
Android Question

Android After Reboot Broadcast Reciver is not running

i used this permisions,

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


and receiver is

<receiver android:name=".auth.NotificationBroadcast"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>


and reciver is

@Override
public void onReceive(Context context, Intent intent) {

System.out.println("BroadcastReceiverBroadcast--------------------ReceiverBroadcastReceiverBroadcastReceiver----------------BroadcastReceiver");

if (intent != null) {
String action = intent.getAction();

switch (action) {
case Intent.ACTION_BOOT_COMPLETED:
System.out.println("Called on REBOOT");
// start a new service and repeat using alarm manager

break;
default:
break;
}
}
}


but after reboot the mobile it is not calling in lollipop,but in marshmellow it is running

Answer

try to put this line in your receiver's intent-filter.

<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />

If your application is installed on the SD card, you should register this to get the android.intent.action.BOOT_COMPLETED event.

Updated: Since your app is using alarm service, it should not be installed on external storage. Reference: http://developer.android.com/guide/topics/data/install-location.html