In one of the exemptions of the "cannot start foreground service from background" restriction, the doc mentions:
Your app invokes an exact alarm to complete an action that the user requests.
Does this mean that the usage scenario below can work?
Use
AlarmManager.setAlarmClock
to schedule an exact alarm to trigger at time A. The alarm carries apendingIntent
that targets a registered broadcast receiver.Time A hits, the receiver gets the intent.
In the receiver
OnCreate
method, we attempt tostartForegroundService
which involves displaying a sticky notification and playing custom music withMediaPlayer
.