< /code>
Я разрабатываю приложение для сигнализации. /> [*] Получатель вещания, после получения действия, начинает службу переднего плана, чтобы воспроизводить носитель. Тем не менее, в моем приложении, когда устройство загружается, мне нужно прослушать действие boot_completed, чтобы я мог перерегистрировать все сигналы тревоги с помощью Alarmmanager на основе данных, хранящихся в базе данных комнаты. Это важно для того, чтобы приложение было правильно функционировать после перезагрузки устройства. Я признал предупреждение и заявил, что планирую решить проблему, но я не уверен, что именно неправильно. Вместо этого я только перерегистрируюсь. Служба переднего плана запускается только позже, когда сигнал тревоги фактически запускается. Тем не менее, я подозреваю, что, поскольку поток от Boot_completed приводит к повторному регистрации тревоги (с действиями по пенсионным и намерениям), которые в конечном итоге вызывают начало службы переднего плана, игровая консоль обнаруживает это как нарушение.@AndroidEntryPoint
class AlarmReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
INTENT_ACTION_APP_ALARM -> {
context.startForegroundService(serviceIntent)
}
}
}
}
< /code>
@AndroidEntryPoint
class AlarmRegisterReceiver : BroadcastReceiver() {
@Inject
lateinit var appAlarmRepository: AppAlarmRepository
@Inject
lateinit var appAlarmManager: AppAlarmManager
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_TIMEZONE_CHANGED -> {
CoroutineScope(Dispatchers.IO).launch {
val appLinkAlarms = appAlarmRepository.alarms.first()
appLinkAlarms.forEach { appLinkAlarm ->
if (appAlarmManager.checkScheduleExactAlarms()) {
appAlarmManager.scheduleAlarm(appLinkAlarm)
}
}
}
}
}
}
}
< /code>
Initially, I handled both BOOT_COMPLETED and my custom INTENT_ACTION_APP_ALARM actions within a single broadcast receiver, separating their logic based on the intent action.
Since I suspected that having code to start a foreground service in the receiver that also listens for BOOT_COMPLETED might be causing the Play Console warning, I refactored my implementation. I split the logic into two separate receivers:
- One receiver handles only the BOOT_COMPLETED action and is responsible for re-registering alarms with the AlarmManager after a device reboot.
- The other receiver is responsible for starting the foreground service when an alarm is triggered.
As I mentioned earlier, my BOOT_COMPLETED receiver only re-registers alarms by scheduling them with the AlarmManager. However, since the flow eventually leads to a foreground service being started (when the alarm goes off via PendingIntent and Intent), I suspect that Google is tracing this entire path and considers it a violation—even though the service is not started directly from BOOT_COMPLETED. I am not certain if this is the actual cause.
I am genuinely unsure how to resolve this issue. Using AlarmManager in this way seems to be the correct approach to provide accurate alarms to users, but I do not know what changes are needed to comply with Play Store policies. Any guidance on how to properly handle this scenario would be greatly appreciated.
Подробнее здесь: https://stackoverflow.com/questions/796 ... -completed