安卓应用程序自动启动权限代码
创始人
2024-11-09 18:31:16
0

在授予应用程序自动启动权限时,可以使用以下代码示例:

//检查应用程序是否允许自动启动 private boolean isAutoStartPermissionGranted() { int result = ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_BOOT_COMPLETED); return result == PackageManager.PERMISSION_GRANTED; }

//请求应用程序自动启动权限 private void requestAutoStartPermission() { Intent intent = new Intent(); intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + getPackageName())); startActivity(intent); }

//检查设备是否支持应用程序自动启动权限 private boolean isAutoStartPermissionSupported() { String manufacturer = android.os.Build.MANUFACTURER; if ("xiaomi".equalsIgnoreCase(manufacturer)) { return true; } else if ("oppo".equalsIgnoreCase(manufacturer)) { return true; } else if ("vivo".equalsIgnoreCase(manufacturer)) { return true; } else if ("huawei".equalsIgnoreCase(manufacturer)) { return true; } else if ("honor".equalsIgnoreCase(manufacturer)) { return true; } return false; }

//启动应用程序自动启动权限设置屏幕 private void startAutoStartPermissionSettingsActivity() { try { Intent intent = new Intent(); String manufacturer = android.os.Build.MANUFACTURER; if ("xiaomi".equalsIgnoreCase(manufacturer)) { intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")); } else if ("oppo".equalsIgnoreCase(manufacturer)) { intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")); } else if ("vivo".equalsIgnoreCase(manufacturer)) { intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")); } else if ("huawei".equalsIgnoreCase(manufacturer)) { intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity")); } else if ("honor".equalsIgnoreCase(manufacturer)) { intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity")); } startActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }

使用这些代码可以解决安卓应用程序自动启动权限的问题。

相关内容

热门资讯

透视详细"wepok... 透视详细"wepoker究竟有没有透视"确实是有辅助app(哔哩哔哩)1、wepoker究竟有没有透...
透视解谜"we-po... 透视解谜"we-poker有人玩吗"确实是有辅助神器(哔哩哔哩)1、we-poker有人玩吗脚本辅助...
透视揭幕"红龙pok... 透视揭幕"红龙poker辅助平台"好像有辅助挂(哔哩哔哩)1、红龙poker辅助平台免费脚本咨询教程...
透视透视"wpk模拟... 透视透视"wpk模拟器多开"其实存在有辅助软件(哔哩哔哩)1、任何wpk模拟器多开透视是真的假的的玩...
透视总结"德州私人局... 透视总结"德州私人局脚本"本来有辅助神器(哔哩哔哩)1、很好的工具软件,可以解锁游戏的德州私人局脚本...
透视教你"红龙pok... 透视教你"红龙poker有辅助吗"真是有辅助技巧(哔哩哔哩)1、红龙poker有辅助吗免费脚本咨询教...
透视解密"poker... 透视解密"pokermaster修改器"真是有辅助工具(哔哩哔哩)1、首先打开pokermaster...
透视解密"德普软件&... 透视解密"德普软件"切实真的有辅助软件(哔哩哔哩)1、很好的工具软件,可以解锁游戏的德普软件辅助插件...
透视揭幕"wepok... 透视揭幕"wepoker数据分析"本来是真的辅助技巧(哔哩哔哩)1、首先打开wepoker数据分析辅...
透视解迷"wepok... 透视解迷"wepoker透视脚本免费"原来真的是有辅助方法(哔哩哔哩)1、这是跨平台的wepoker...