I have critical reminders that are configured through the Alarm Manager (it should work just like the alarm application).
I used to have the following in Android Manifest:
<receiver android:name="com.example.app.AlarmReceiver" > <intent-filter> <action android:name="${packageName}.alarm.action.trigger"/> </intent-filter> </receiver>
Broadcast Receiver:
public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive( final Context context, final Intent intent) {
How to set the alarm:
final PendingIntent operation = PendingIntent.getBroadcast( mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT); if (PlatformUtils.hasMarshmallow()) { alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtMillis, operation); } else { alarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis, operation); } }
In Android 8.0, I can no longer use implicit broadcasting as defined in the manifest. In this case, the alternative is to manually register as follows:
final BroadcastReceiver receiver = new AlarmReceiver(); final IntentFilter intentFilter = new IntentFilter(ALARM_RECEIVER_INTENT_TRIGGER); context.registerReceiver(receiver, intentFilter);
This does not seem logical to me.
The alarm receiver will be bound to the context lifetime. This causes a problem when they say that the application is killed due to memory pressure or when the device restarts. I need my alarms to light up every time, as they are critical to the user's health.
Even if I listen to “android.intent.action.BOOT_COMPLETED” and register the alarm receiver, the application will be killed shortly after that and no alarm will be launched. I also do not see my alarm through
adb shell dumpsys alarm
How to create a custom broadcast receiver that receives implicit broadcasts to give an alarm when setting up Android O (8.0)? Can someone enlighten me with a code example or a link to the documentation. How does the Timely app or any other alarm app work when targeting O?
source share