【发布时间】:2015-12-06 04:52:15
【问题描述】:
我是 Google Play 上两个闹钟应用的开发者。我试图让他们使用 Android 6.0。但是,打瞌睡模式使它不会响铃。我把它们放在白名单上,我放了一个前台通知图标,我不确定我还能做什么 - 在打盹模式下,警报管理器警报仍然被忽略。但是,时钟应用程序(它是一个 Google Play 而不是 AOSP 应用程序)是不同的。在时钟应用上启用闹钟后,“adb deviceidle step”将始终显示为“active”,而不会显示为“idle”、“idle_pending”或其他任何内容。
Android 是否在这里作弊,赋予自己的应用更多的功能,又名。 “拉苹果”? Google Play 上的所有闹钟应用程序都将无法使用吗?有点担心,这些都是高质量的应用程序,每个都需要一年的兼职开发时间,对我来说是很大的收入来源。任何关于我如何让这些工作的线索都会有很大的帮助。
设置 AlarmManager 意图:
Intent intent = new Intent(context, ReceiverAlarm.class);
if (android.os.Build.VERSION.SDK_INT >= 16) {
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
}
amSender = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT); //FLAG_CANCEL_CURRENT seems to be required to prevent a bug where the intent doesn't fire after app reinstall in KitKat
am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, scheduleToTime+1, amSender);
和 ReceiverAlarm 类:
public class ReceiverAlarm extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (wakeLock == null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Theme.appTitle);
wakeLock.acquire();
}
X.alarmMaster.startRingingAlarm(true);
}
以及 X.alarmMaster.startRingingAlarm() 方法的相关部分:
if (wakeLock == null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Theme.appTitle);
wakeLock.acquire();
}
if (screenWakeLock == null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
screenWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, Theme.appTitle+" scr");
screenWakeLock.acquire();
}
Intent alarmIntent = new Intent(Intent.ACTION_VIEW);
alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
alarmIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
alarmIntent.setClass(context, ActivityAlarmAlarm.class);
context.startActivity(alarmIntent);
为了便于阅读,部分方法已被内联粘贴。
【问题讨论】:
-
让我们有一些 sn-ps 可以帮助其他人了解正在发生的事情。请:-)
-
当然,我会编辑我的回复。它们都是 20k+ 行代码,所以我将尝试为其中之一发布相关行。
-
有趣,有什么帮助吗? alarm clocks riddle
标签: android alarmmanager android-6.0-marshmallow