最近在做项目的过程中遇到了以下一个需求,虽然看起来不难实现,但是在实现的过程中遇到了各种坑,记录一下,今后方便查看! ! !
用户第一次安装应用程序,点击授权按钮,跳转至授权的页面(不同手机跳转到不同的授权页面),用户授权成功之后,点击返回按钮,直接进入主页面
1。如何适配不同机型
2。不同机型的授权页面显示不同弹窗(比如三星显示悬浮窗,小米显示弹窗)
3。小米弹窗始终无法显示
4。在授权页面点击返回按钮,怎么直接跳转到主页面
<强>问题1:适配不同机型强>
这个是借鉴的一篇博文(忘记地方了,后边找到了再添加~ ~)
公开课MobileInfoUtils { 私人SettingDialogPermision dialog_per;//获取手机类型 私有静态字符串getMobileType () { 返回Build.MANUFACTURER; }//跳转至授权页面 公共空间jumpStartInterface(上下文语境){ 目的意图=new意图(); 尝试{ intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); 日志。e (“HLQ_Struggle”、“* * * * * * * * * * * * * * * * * *当前手机型号为:" + getMobileType ()); ComponentName ComponentName=零; 如果(getMobileType () .equals(“小米”)){//红米Note4测试通过 componentName=new componentName (“com.miui。securitycenter”、“com.miui.permcenter.autostart.AutoStartManagementActivity”); }else if (getMobileType () .equals (“Letv”)){//乐视2测试通过 intent.setAction (“com.letv.android.permissionautoboot”); }else if (getMobileType () .equals(“三星”)){//三星Note5测试通过//componentName=new componentName (“com.samsung.android。sm_cn”、“com.samsung.android.sm.ui.ram.AutoRunActivity”);//componentName=ComponentName.unflattenFromString (" com.samsung.android.sm/.ui.ram.RamActivity ");//许可否认不出口的uid 1000,不允许被其他程序调用 componentName=ComponentName.unflattenFromString (“com.samsung.android.sm/.app.dashboard.SmartManagerDashBoardActivity”); }else if (getMobileType () .equals(“华为”)){//华为测试通过//componentName=new componentName (“com.huawei。systemmanager”、“com.huawei.systemmanager.optimize.process.ProtectActivity ");//锁屏清理 componentName=ComponentName.unflattenFromString (" com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity ");//跳自启动管理//SettingOverlayView.show(上下文); }else if (getMobileType () .equals(“体内”)){//vivo测试通过 componentName=ComponentName.unflattenFromString (“com.iqoo.secure/.safeguard.PurviewTabActivity”); }else if (getMobileType () .equals(“魅族”)){//万恶的魅族//componentName=ComponentName.unflattenFromString (" com.meizu.safe/.permission.PermissionMainActivity ");//跳转到手机管家 componentName=ComponentName.unflattenFromString (" com.meizu.safe/.permission.SmartBGActivity ");//跳转到后台管理页面 }else if (getMobileType () .equals(“朋友”)){//同僚R8205测试通过 componentName=ComponentName.unflattenFromString (“com.oppo.safe/.permission.startup.StartupAppListActivity”); }else if (getMobileType () .equals (“ulong”)){//360手机未测试 componentName=new componentName (“com.yulong.android。coolsafe”、“.ui.activity.autorun.AutoRunListActivity”); 其他}{//将用户引导到系统设置页面 如果(Build.VERSION。SDK_INT祝辞=9){ 日志。e (“HLQ_Struggle”、“APPLICATION_DETAILS_SETTINGS”); intent.setAction (“android.settings.APPLICATION_DETAILS_SETTINGS”); intent.setData (Uri.fromParts(“包”,context.getPackageName (), null)); 如果(Build.VERSION}其他。SDK_INT & lt;=8) { intent.setAction (Intent.ACTION_VIEW); intent.setClassName (“com.android。设置”、“com.android.settings.InstalledAppDetails”); intent.putExtra (“com.android.settings。ApplicationPkgName”, context.getPackageName ()); } } intent.setComponent (componentName); context.startActivity(意图); 如果(getMobileType () .equals(“小米”)){ showtip();//显示弹窗(* *特别注意* *) } 如果(getMobileType () .equals(“三星”)){ 新的SettingOverlayView(),告诉(上下文);//显示悬浮窗 } }捕捉(异常e){//抛出异常就直接打开设置页面 日志。e (“HLQ_Struggle e.getLocalizedMessage ()); 意图=new意图(Settings.ACTION_SETTINGS); context.startActivity(意图); } }//小米手机显示弹窗 私人空间showtip () { 尝试{ dialog_per=new SettingDialogPermision(上下文,R.style.CustomDialog4); dialog_per.getWindow () .setType (WindowManager.LayoutParams.TYPE_TOAST);//注意这里改成吐司类型 dialog_per.show (); Log.e (“HLQ_Struggle”、“显示弹窗”); }捕捉(异常e) { e.printStackTrace (); 日志。e (“HLQ_Struggle”、“没有显示弹窗”+ e.getMessage ()); } } }android引导用户开启自启动权限的方法