BroadcastReceiver не работает для каких-либо действий в Api 26 или выше, в соответствии с документацией неявные действия блокируются, но не boot_completed. Я проверил с Android 19, 24, 26 и 28.
Вот моя декларация получателя:
<receiver
android:name="de.com.limto.limto1.broadcastReceiver"
android:label="StartMyServiceAtBootReceiver"
android:directBootAware="true"
android:enabled="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
<action android:name="android.intent.action.REBOOT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</receiver>
и здесь мои разрешения
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
и здесь мой приемник:
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.d(BROADCAST_RECEIVER,intent.getAction());
lib.appendLog(intent.getAction(),context);
lib.ShowToast(context, BROADCAST);
if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
if (service != null) {
try {
service.stop();
} catch (Throwable throwable) {
throwable.printStackTrace();
Log.e(BROADCAST_RECEIVER,throwable.getMessage(), throwable);
}
}
} else {
/*if (service != null) return;
Intent serviceIntent;
serviceIntent = new Intent(context, LimindoService.class);
serviceIntent.putExtra(BOOT, true);
*/
LimindoService.ccontext = context;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//context.startService(serviceIntent);
lib.scheduleJob(context);
} else {
//context.startService(serviceIntent);
startServiceByAlarm(context);
}
}
}
catch (Throwable ex)
{
ex.printStackTrace();
lib.appendLog(ex.getMessage(), context);
Log.e(BROADCAST_RECEIVER,null,ex);
lib.ShowToast(context, ex.getMessage());
}
}