如何使报警管理工作的打盹模式时的Andr​​oid 6.0? [英] How to make Alarm Manager work when Android 6.0 in Doze mode?

查看:200
本文介绍了如何使报警管理工作的打盹模式时的Andr​​oid 6.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是两个闹钟应用程序在谷歌开发者播放。我试图让他们与Android 6.0的工作。然而,打盹模式使得它,使他们不响。我把他们的白名单,我把前台通知图标了,我不知道还有什么我可以做的 - 当在打盹模式后,报警管理器的报警仍在忽略。时钟应用程序(其是谷歌播放而非AOSP应用程序),但是,是不同的。报警时的时钟应用程序启用后,亚行deviceidle一步将始终读积极,也不会闲置,idle_pending或其他任何东西。

I am a developer of two alarm clock apps on Google Play. I am trying to get them to work with Android 6.0. However, Doze mode makes it so they do not ring. I put them on the white list, I put a foreground notification icon up, I'm not sure what else I can do - when in Doze mode, the the Alarm Manager alarms are still ignored. The Clock app (which is a Google Play rather than AOSP app), however, is different. When the alarm is enabled on the Clock app, "adb deviceidle step" will always read "active" and never "idle", "idle_pending" or anything else.

是Android的欺骗在这里,让自己的应用程序更多的权力,又名。 拉一个苹果?是否对谷歌所有的闹钟应用程序播放即将成为非功能?那种担心这里,这些都是优质的应用程序,每个花了一年的兼职开发时间,而且都是大收入来源,对我来说。我如何能得到这些工作的任何线索,将是一个巨大的帮助。

Is Android cheating here, giving its own app more power, aka. "pulling an apple"? Are all alarm clock apps on Google Play about to become non-functional? Kind of worried here, these are quality apps that each took a year of part-time development time, and are big income sources for me. Any clues on how I could get these to work would be a huge help.

设置AlarmManager意图:

Setting the 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类:

and the ReceiverAlarm class:

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()方法的相关部分:

and the relevant parts of the X.alarmMaster.startRingingAlarm() method:

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

有些方法已经被粘贴内联,方便阅读。

Some of the methods have been pasted inline for easier readability.

推荐答案

打盹和App待机绝对改变关于警报和wakelocks的行为,但他们绝对不是世界末日为您服务!

Doze and App Standby definitely change the behavior in regards to alarms and wakelocks, but they're definitely not the end of the world for you!

您是否尝试过使用方法<一href="https://developer.android.com/reference/android/app/AlarmManager.html#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,%20android.app.PendingIntent)"><$c$c>setAlarmclock()而不是设置()? 它特别为闹钟而设计,可能能够通过瞌睡削减。有几个亚行命令,你可以使用手动把手机变成瞌睡或应用程序的待机模式:<一href="https://developer.android.com/$p$pview/features/power-mgmt.html">https://developer.android.com/$p$pview/features/power-mgmt.html

Have you tried using the method setAlarmclock() instead of set()? It's designed specifically for alarm clocks and may be able to cut through doze. There are a few adb commands you can use to manually put a phone into doze or app standby mode: https://developer.android.com/preview/features/power-mgmt.html

如果不是能够唤醒你的应用程序了,还有的万无一失的方法<一href="https://developer.android.com/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)"><$c$c>setExactAndAllowWhileIdle()旨在从打盹醒来的手机不管是什么。最坏的情况,你可以唤醒你的应用程序了这种方法,并使用唤醒计划下一次警钟。

If that isn't able to wake your app up, there's the surefire method setExactAndAllowWhileIdle() is designed to wake the phone from doze no matter what. Worst case scenario, you can wake your app up with this method and use the wakeup to schedule the next alarm.

另一页值得一读的这篇博客文章,其流程图后台工作,并报警:<一href="https://plus.google.com/+AndroidDevelopers/posts/GdNrQciPwqo">https://plus.google.com/+AndroidDevelopers/posts/GdNrQciPwqo

Another page worth a read is this blog post with its flowchart for background work and alarms: https://plus.google.com/+AndroidDevelopers/posts/GdNrQciPwqo

让我知道这对你的作品!

Let me know how this works for you!

这篇关于如何使报警管理工作的打盹模式时的Andr​​oid 6.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆