组特定应用程序忽略在版本的Andr​​oid M code优化 [英] Set specific App to ignore optimization by code in Android M

查看:819
本文介绍了组特定应用程序忽略在版本的Andr​​oid M code优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新的版本的Andr​​oid M 打造,电池优化功能将停止在一定条件下的应用程序,以节省电池,但对于 VOIP 需要生存的所有时间的应用程序,这个功能肇事的开发者。

In the new Android M build, the Battery Optimization feature will stop the app on certain condition to save battery, but for the VOIPapps that need to stay alive all the time, this feature cause troubles for the developer.

目前有绕过优化,这是设置应用程序忽略最佳方式之一,但太多的步骤需要完成。

Currently there is one way to bypass the optimization, which is set the app to ignore optimizations,but too many steps need to be done.

我的问题是,有没有办法跳忽略特定应用优化页面,我怎么能知道是否我的应用程序从优化排除?

My question is, is there a way to jump to ignore optimization page of specific App, and how can I know whether my app is excluded from optimization?

推荐答案

警告:好像谷歌不允许在Play商店中的应用程序做到这一点。请参阅下面的注释。

根据从Settings.apk在MPA44I打造提取的Andr​​oidManifest.xml中,似乎你也许可以通过类似下面的意图,做你想做的。

Based on the AndroidManifest.xml extracted from Settings.apk in the MPA44I build, it would seem you might be able to do what you want by something like the intent below.

从XML:

<intent
    android:action="android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"
    android:targetPackage="com.android.settings"
    android:data="package:PUT_YOUR_PACKAGE_NAME_HERE" />

从code:

try {
    Intent intent = new Intent(android.provider.Settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
    intent.setData(Uri.parse("package:PUT_YOUR_PACKAGE_NAME_HERE"));
    startActivity(intent);

} catch (ActivityNotFoundException e) {
    e.printStackTrace();
}

请注意,我还没有来得及在实践中验证这一点,但我自己的方法是一样的,因为我在我的应用程序之一,它启动特定应用的设置菜单。不过,我希望它能帮助。

Note that I have not had time to verify this in practice myself but the approach is the same as I use in one of my apps to launch app-specific settings menus. Still, I hope it helps.

这篇关于组特定应用程序忽略在版本的Andr​​oid M code优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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