android - 如何设置多个每日闹钟?

标签 android

我想在我的 android 应用程序中设置多个每日闹钟,因为我正在制作这样的演示代码

Intent i = new Intent(this, AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i,PendingIntent.FLAG_ONE_SHOT);

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 1);

AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 30000, pi);

我给了 30000 毫秒作为间隔,所以我认为它应该每 30 秒重复一次。但不重复。我启动应用程序 1 分钟后它响了一次是我错了吗?我应该怎么做才能在我的应用程序中设置多个每日警报? 谢谢!

最佳答案

我认为你的问题在于你的 PendingIntent 带有标志 FLAG_ONE_SHOT,所以你只能设置一次闹钟。如果您想要重复闹钟,请尝试使用标志 FLAG_UPDATE_CURRENT

来源:http://developer.android.com/reference/android/app/PendingIntent.html

关于android - 如何设置多个每日闹钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13087715/

相关文章:

android - 如何在创建 DialogFragment 时关闭 Activity?

android - 在 Flutter 项目的 android studio 上初始化 Gradle 将永远存在

android - 如何为html页面android web View 加载css文件

android - AsyncTask 和 Firebase

android - 在 android 中使用 Intent 将图像分享到另一个应用程序

android - 如何将 String 转换为 Drawable

android - android属性中格式引用的含义

android - 使用自定义参数链接到 Google Play 商店

iphone - 我对 AR 应用程序中指南针和 GPS 功能的理解是否正确?

android - 在 WebView 中打开 PDF 文件