安卓应用程序自动启动权限代码
创始人
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(); } }

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

相关内容

热门资讯

外挂课程!wepoker安装教... 外挂课程!wepoker安装教程,sohoopoker辅助-一贯存在有辅助脚本(哔哩哔哩)wepok...
外挂教程书!pokerworl... 外挂教程书!pokerworld修改器,拱趴大菠萝万能挂-原来一直都是有辅助技巧(哔哩哔哩)外挂教程...
外挂妙招!德州私人局怎么透视,... 外挂妙招!德州私人局怎么透视,约局吧如何查看是否有挂-其实一直都是有辅助教程(哔哩哔哩)1、超多福利...
外挂积累!约局吧德州透视,po... 外挂积累!约局吧德州透视,poker world辅助器-本来有辅助插件(哔哩哔哩)约局吧德州透视辅助...
外挂学习!德州透视脚本,aa ... 外挂学习!德州透视脚本,aa poker辅助-一直一直总是有辅助插件(哔哩哔哩)1、这是跨平台的德州...
外挂模块!德州局脚本,xpok... 外挂模块!德州局脚本,xpoker辅助器-真是一直总是有辅助技巧(哔哩哔哩)1、起透看视 德州局脚本...
外挂法子!德普之星透视辅助软件... 外挂法子!德普之星透视辅助软件是真的吗,哈糖大菠萝可以开挂吗-真是是有辅助方法(哔哩哔哩)1、哈糖大...
外挂方针!竞技联盟破解版最新版... 外挂方针!竞技联盟破解版最新版,xpoker辅助-确实存在有辅助技巧(哔哩哔哩)1、该软件可以轻松地...
外挂攻略!红龙poker辅助,... 外挂攻略!红龙poker辅助,德普之星透视-真是有辅助脚本(哔哩哔哩)1、红龙poker辅助公共底牌...
外挂妙招!uupoker透视,... 外挂妙招!uupoker透视,sohoo开挂辅助-确实有辅助方法(哔哩哔哩);sohoo开挂辅助破解...