Execução em segundo plano não permitida. Android O pendente
Eu tenho um serviço que agende um item pendente que inicia minha notificação. No entanto, desde o Android O, estou recebendo esse erro. Eu fiz algumas pesquisas e me deparei comcontext.registerReceiver
, mas isso não parece resolver o problema.
Erro:
W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_ADDED dat=package:my.great.package flg=0x4000010 (has extras) } to com.google.android.googlequicksearchbox/com.google.android.apps.gsa.googlequicksearchbox.GelStubAppWatcher
`` ``
Meu pendente:
Intent myNotification = new Intent("services.notifications.Notification");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, (int) (Math.random() * Integer.MAX_VALUE), myNotification, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) (this.getSystemService(Context.ALARM_SERVICE));
alarmManager.setExact(AlarmManager.RTC_WAKEUP, day.getTimeInMillis(), pendingIntent);
Minha notificação:
public class Notification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.registerReceiver(this, new IntentFilter());
try {
WakeLock wakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)).newWakeLock(1, "NotificationWakeLock");
wakeLock.acquire(10000);
try {
scheduleNotification(context, intent);
} finally {
wakeLock.release();
}
} catch (NullPointerException e) {}
}
}