You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

仅用非精确闹钟却遭Play Store SCHEDULE_EXACT_ALARM警告求助

Play Store精确闹钟权限警告排查

问题描述

Play Store收到以下警告:

Your use of exact alarms is causing your app to crash for some Android users
Your app schedules exact alarms without checking whether the SCHEDULE_EXACT_ALARM permission has been granted. This is causing your app to crash for users on Android 14 because the permission is no longer granted by default.

In most cases, alternative methods of scheduling work or inexact alarms are more appropriate. If your use of exact alarms is justified, update your app so that it checks this permission is granted before scheduling.

但我明确仅通过以下代码触发非精确闹钟:

val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val alarmIntent =
    Intent(context, MediaDownloadAlarmReceiver::class.java).let { intent ->
        PendingIntent.getBroadcast(
            context,
            0,
            intent,
            PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
    }

val calendar =
    Calendar.getInstance().apply {
        timeInMillis = System.currentTimeMillis()
        set(Calendar.HOUR_OF_DAY, 5)
        set(Calendar.MINUTE, 0)
    }

// Set the alarm to start at approximately 5:00 a.m.
alarmManager.setInexactRepeating(
    AlarmManager.RTC_WAKEUP,
    calendar.timeInMillis,
    AlarmManager.INTERVAL_DAY,
    alarmIntent)

闹钟触发后,调度一次性Worker请求:

override fun onReceive(context: Context?, intent: Intent?) {
    if (context != null) {
        MediaDownloadWorker.scheduleOneTimeRequest(
            context = context,
            source = "background_process")
    }
}

请问我遗漏了什么?

可能的排查方向

  • 第三方库隐式调用精确闹钟:检查项目所有依赖的SDK(推送、统计、后台任务类库等),部分库可能在内部使用setExact()、setExactAndAllowWhileIdle()这类精确闹钟API,Play Store的检测会扫描整个APK的代码引用,包括第三方库的字节码。
  • 检查MediaDownloadWorker实现:确认Worker内部是否调用了精确闹钟相关方法,比如在Worker逻辑里需要触发定时任务时误用了精确闹钟API。
  • AndroidManifest权限检查:查看清单文件是否意外声明了SCHEDULE_EXACT_ALARM权限,若声明了该权限,Android 14默认不授权,若代码中存在未做权限检查的精确闹钟调用(哪怕是第三方库的),就会导致崩溃触发警告。
  • 代码混淆的误判:如果开启了混淆,检查混淆规则是否正确保留了AlarmManager相关方法,部分混淆可能导致静态分析工具误判代码中存在精确闹钟调用。
  • 系统版本适配的特殊情况:虽然setInexactRepeating()本身是非精确闹钟,但如果设置的首次触发时间是过去的时间,系统可能会立即触发一次,不过这种情况一般不会触发权限问题,可作为次要排查点。

内容的提问来源于stack exchange,提问作者Ana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 16:33:34