首页 > 解决方案 > 为 Android 10 开发自定义闹钟

问题描述

我有自定义闹钟应用程序。当警报触发时,我的活动开始。这适用于 Android 9,但不适用于后台的 Android 10 [限制从后台启动活动][1]。谷歌建议启动通知而不是活动,但我不太明白如何使用通知显示警报触发。是否有其他解决方案来显示警报触发?

final PendingIntent alarmIntent = getAlarmActivityIntent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    PendingIntent showIntent = getShowIntent();
    AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(ringAt, showIntent);
    if (am != null)
     am.setAlarmClock(info, alarmIntent);```


  [1]: https://developer.android.com/guide/components/activities/background-starts#display-notification

标签: androidandroid-10.0

解决方案


推荐阅读