gpt4 book ai didi

android - Android 6.0 处于打盹模式时如何让闹钟管理器工作?

转载 作者:IT王子 更新时间:2023-10-28 23:48:58 26 4
gpt4 key购买 nike

我是 Google Play 上两个闹钟应用的开发者。我试图让他们使用 Android 6.0。但是,打瞌睡模式使它不会响铃。我把它们放在白名单上,我放了一个前台通知图标,我不确定我还能做什么 - 在打盹模式下,警报管理器警报仍然被忽略。但是,时钟应用程序(它是一个 Google Play 而不是 AOSP 应用程序)是不同的。在时钟应用上启用闹钟后,“adb deviceidle step”将始终显示为“active”,而不会显示为“idle”、“idle_pending”或其他任何内容。

Android 是否在这里作弊,赋予自己的应用更多的功能,又名。 “拉苹果”? Google Play 上的所有闹钟应用程序都将无法使用吗?有点担心,这些都是高质量的应用程序,每个都需要一年的兼职开发时间,对我来说是很大的收入来源。任何关于我如何让这些工作的线索都会有很大的帮助。

设置 AlarmManager Intent :

        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);

为了便于阅读,部分方法已被内联粘贴。

最佳答案

Doze 和 App Standby 肯定会改变警报和唤醒锁的行为,但它们绝对不是你的世界末日!

你试过用setAlarmclock()的方法吗?而不是 set()?它是专为闹钟设计的,可以打瞌睡。您可以使用一些 adb 命令手动将手机置于打盹或应用待机模式:https://developer.android.com/preview/features/power-mgmt.html

如果这不能唤醒您的应用程序,有一个万无一失的方法 setExactAndAllowWhileIdle()旨在无论如何将手机从打盹中唤醒。在最坏的情况下,您可以使用此方法唤醒您的应用,并使用唤醒来安排下一个闹钟。

另一个值得一读的页面是这篇博客文章,其中包含后台工作和警报的流程图:https://plus.google.com/+AndroidDevelopers/posts/GdNrQciPwqo

关于android - Android 6.0 处于打盹模式时如何让闹钟管理器工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32492770/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com