Android6.0 打开自启动管理页面(华为、小米)

Android在6.0之后就禁止了APP拉起其他的APP,这样子在一些推送服务无法通过拉起其他APP来接受通知,当你的APP没有在线状态下是收不到推送的,包括华为推送和小米推送,小米推送还好一点,可以通过推送系统的通知实现推送,但是推送自定义消息就无法送达了。当然,如果我们打开了APP的自启动权限后是可以收到华为推送和小米推送的,它通过系统把我们的APP启动起来然后就可以收到推送了。当然,要打开自启动权限必须通过手动去打开,我们只能引导用户手动去打开,就像触宝电话那样可以通过引导用户去打开权限。那么我们怎么可以快速的打开自启动页面呢,其实通过代码是可以打开的。
/*打开自启动管理页*/
	public static void openStart(Context context){
		if(Build.VERSION.SDK_INT < 23){
			return;
		}
		String system = getSystem();
		Intent intent = new Intent();
		if(system.equals(SYS_EMUI)){//华为
			ComponentName componentName = new ComponentName("com.huawei.systemmanager","com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");
			intent.setComponent(componentName);
		}else if(system.equals(SYS_MIUI)){//小米
			ComponentName componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");
			intent.setComponent(componentName);
		}
		try{
			context.startActivity(intent);
		}catch (Exception e){//抛出异常就直接打开设置页面
			intent=new Intent(Settings.ACTION_SETTINGS);
			context.startActivity(intent);
		}
	}
当然,首先要判断是小米系统还是华为系统,在http://blog.csdn.net/jin_qing/article/details/53087164里面有介绍

猜你喜欢

转载自blog.csdn.net/mmmccc000/article/details/53335644