android 自启动权限,引导用户开启开机自启动权限

跳转到开启自启动权限页

/**

* 获取自启动管理页面的Intent

* @param context context

* @return 返回自启动管理页面的Intent

* */

public static Intent getAutostartSettingIntent(Context context) {

ComponentName componentName = null;

String brand = Build.MANUFACTURER;

Intent intent = new Intent();

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

switch (brand.toLowerCase()) {

case "samsung"://三星

componentName = new ComponentName("com.samsung.android.sm", "com.samsung.android.sm.app.dashboard.SmartManagerDashBoardActivity");

break;

case "huawei"://华为

//荣耀V8,EMUI 8.0.0,Android 8.0上,以下两者效果一样

componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity");

// componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");//目前看是通用的

break;

case "xiaomi"://小米

componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");

break;

case "vivo"://VIVO

// componentName = new ComponentName("com.iqoo.secure", "com.iqoo.secure.safaguard.PurviewTabActivity");

componentName = new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity");

break;

case "oppo"://OPPO

// componentName = new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity");

componentName = new ComponentName("com.coloros.oppoguardelf", "com.coloros.powermanager.fuelgaue.PowerUsageModelActivity");

break;

case "yulong":

case "360"://360

componentName = new ComponentName("com.yulong.android.coolsafe", "com.yulong.android.coolsafe.ui.activity.autorun.AutoRunListActivity");

break;

case "meizu"://魅族

componentName = new ComponentName("com.meizu.safe", "com.meizu.safe.permission.SmartBGActivity");

break;

case "oneplus"://一加

componentName = new ComponentName("com.oneplus.security", "com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity");

break;

case "letv"://乐视

intent.setAction("com.letv.android.permissionautoboot");

default://其他

intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");

intent.setData(Uri.fromParts("package", context.getPackageName(), null));

break;

}

intent.setComponent(componentName);

return intent;

}

Android中,启动某个应用程序时需要获取相应的权限。以下是一些示例代码,用于在Android中启用自启动权限。 在AndroidManifest.xml文件中添加以下代码: ``` <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> ``` 然后,可以在Activity或Service中添加以下代码: ``` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + getPackageName())); startActivity(intent); } ``` 这段代码将打开一个名为“Battery Optimization”的设置界面。在这个设置界面中,用户可以允许应用程序在系统启动时自动启动。 注意:这段代码只能在Android 8.0及以上版本中使用。在Android 8.0以下版本中,可以使用以下代码: ``` 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")); } List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() > 0) { startActivity(intent); } ``` 这段代码将打开各个厂商设备的自启动管理界面,用户可以在该界面中允许应用程序在系统启动时自动启动。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值