当前位置:   article > 正文

小米手机电量和性能的白名单_miui14电池白名单

miui14电池白名单

         小米手机Note 3有个“电量和性能”设置,如果没有把app设置为无限制,侧app在后台很容易被杀,导致每次重新启动app,针对该情况,做了个判断

  1. /**
  2. * 电池优化设置
  3. */
  4. object BatteryOptimization {
  5. /**
  6. * 判断当前APP是否有加入电池优化的白名单(目前只限于小米 Note3手机)
  7. */
  8. fun isIgnoreBatteryOptimization(activity: Activity?):Boolean {
  9. val powerManager: PowerManager? = activity?.getSystemService(Context.POWER_SERVICE) as? PowerManager
  10. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  11. val hasIgnored: Boolean? = powerManager?.isIgnoringBatteryOptimizations(activity?.packageName)
  12. return hasIgnored ?: true
  13. }
  14. return true
  15. }
  16. /**
  17. * 弹出加入电池优化的白名单的设置对话框(目前只限于小米 Note3手机)
  18. * @param appName app名字
  19. */
  20. fun ignoreBatteryOptimizationSetting(activity: Activity?,appName: String) {
  21. val intent = Intent(activity?.packageName)
  22. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  23. //电量和性能--小马达配置
  24. val componentName = ComponentName("com.miui.powerkeeper", "com.miui.powerkeeper.ui.HiddenAppsConfigActivity")
  25. intent.component = componentName
  26. intent.putExtra("package_name", activity?.packageName);
  27. intent.putExtra("package_label", appName)//activity.resources.getString(R.string.app_name)
  28. val resolveInfos: List<ResolveInfo>? = activity?.packageManager?.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
  29. if (resolveInfos.isNullOrEmpty().not()) {
  30. activity?.startActivity(intent)
  31. }
  32. }
  33. }

参考以下链接:
https://blog.csdn.net/qq_36237165/article/details/104200749?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-6&spm=1001.2101.3001.4242

https://blog.csdn.net/qq_41563374/article/details/103079582?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-3&spm=1001.2101.3001.4242

https://blog.csdn.net/wxz1179503422/article/details/56671609/

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/466440
推荐阅读
相关标签
  

闽ICP备14008679号