如何在 Android 6.0 打盹模式下将应用列入白名单 [英] How to WhiteList app in Doze mode Android 6.0

查看:42
本文介绍了如何在 Android 6.0 打盹模式下将应用列入白名单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与Android 6.0 Preview 3 相关,Android 6.0 Preview 3 将于本月底最终发布.

This question is related to the Android 6.0 Preview 3 which will be final released at the end of this month.

我正在 Nexus 5hammerhead"上的 Google 预览版 3 中测试 Android 6.0 中的一些内容.

I'm testing some stuff in Android 6.0 in the preview 3 from Google on Nexus 5 'hammerhead'.

新功能是打盹模式"——类似于深度睡眠模式,当网络被禁用且手机处于睡眠状态时,只有短信、电话或高优先级 GCM 消息才能将其唤醒.但就像 WhatsApp - 在打盹模式下,它会在 2 小时或更长时间后收到消息,具体取决于计时器.但是有一个名为白名单"的未优化"应用列表,您可以在其中手动添加应用.

The new feature is the "doze mode" - something like deep sleep mode when the network is disabled and phone sleeps, only the SMS, calls or high priority GCM messages can wake it up. But like WhatsApp - in the doze mode it receives the messages after 2 hours or more depends on the timers. But there is a list of 'not optimised' apps called "white list" where u can manually add app.

好的,我想找到一种方法,以编程方式将我的应用程序添加到设备中电池设置中存在的白名单应用程序列表"中,而无需用户交互.

Ok, I'd like to find a way to add my application programmatically without user interaction to the "white list app list" which exists in the device in battery settings.

尝试使用反射进入它我发现:

Trying to use the reflection to get into it I found:

在 android.os.IDeviceIdleController 中有一个方法:

Within the android.os.IDeviceIdleController there is a method:

public abstract void addPowerSaveWhitelistApp (String packageNameOfApp)

public abstract void addPowerSaveWhitelistApp (String packageNameOfApp)

但这是一个接口......所以我们不能创建接口的实例.

But this is an interface... So we can not make an instance of interface.

目前还没有关于这个接口、方法或任何继承树的文档.

There is not yet documentation about this Interface or about methods, or any inheritance tree.

也许你知道我应该在哪里寻找以编程方式添加我的应用程序的可能性?

Maybe you have some idea where i should look for a possibility of programmatically add there my app?

还有一个方法

public abstract boolean isPowerSaveWhitelistApp (String packageName)

public abstract boolean isPowerSaveWhitelistApp (String packageName)

我认为应该可以以某种方式访问​​?!检查应用程序是否存在于白名单中,也许在最后希望要求用户将其添加到白名单中.

Which i think should be possible to access somehow?! to check if the app exist on the White List and maybe at the very end hopefully ASK user to add it to the White List.

所以我的问题是,你们有没有人尝试过做出更好结果的东西?因为我被卡住了,我认为这是一个死胡同.

So my question is, have anyone of you tried to make something with better result ?? cuz I'm stuck and i think its a dead end.

了解更多信息:https://newcircle.com/s/post/1739/2015/06/12/diving-into-android-m-doze

推荐答案

添加权限

<uses-permission 
android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

请求将您的应用列入白名单

request whitelist your app

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    Intent intent = new Intent();
    String packageName = getPackageName();
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    if (!pm.isIgnoringBatteryOptimizations(packageName)) {
        intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
        intent.setData(Uri.parse("package:" + packageName));
        startActivity(intent);
    }
}

这篇关于如何在 Android 6.0 打盹模式下将应用列入白名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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