android - 为 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
解决方案
推荐阅读
- react-native - FlatList 项目占用全部可用高度?
- node.js - 如何修复firebase功能未处理的错误错误
- keras - TimeSeries 用例:如何在 VAE 网络(降噪器)之上插入 LSTM 网络(预测器)
- ios - macOS 上的 SwiftUI 嵌套滚动视图问题
- c# - WebRequest 类的 .Create(url) 方法不起作用
- python - 给定具有开始和结束索引的数据框创建多个切片
- android - 没有来自 MediaSessionCompat.Callback() 的回调
- ruby-on-rails - 如何提交一组复选框,以便数组中的每个元素都有一个(但只有一个)值?
- debugging - Firefox(v82、v83)(32 位)调试器 - 内联变量预览未启用 - 如何解决?
- php - 如何使用自定义产品属性值更新 woocommerce 销售价格?