续上一篇《Android的权限设置及自启动设置》,在开发中我通过一个按钮来进行跳转到系统的权限页面,一开始的代码就是上一篇中的原模原样的代码,如下所示:

    /**     * 跳转到权限设置界面     */    private void getAppDetailSettingIntent(Context context){        Intent intent = new Intent();        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        if(Build.VERSION.SDK_INT >= 9){            intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");            intent.setData(Uri.fromParts("package", getPackageName(), null));        } else if(Build.VERSION.SDK_INT <= 8){            intent.setAction(Intent.ACTION_VIEW);            intent.setClassName("com.android.settings","com.android.settings.InstalledAppDetails");            intent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());        }        startActivity(intent);    }

然而,把公司里的安卓都借来测了一遍后只想感叹:理想很丰满,现实很骨感!

首先呢,公司里的手机只有小米(好多只)、vivo(两只)、三星(一只)、oppo(一只)。

测试结果:
小米,没有问题,跳转到页面后直接选择权限管理就可以设置了;
vivo,跳转到的权限页面只给看,不能设置;
三星,这一只没问题;
oppo,和vivo一样,跳转到的权限页面只给看,不能设置。

这实在是好坑,oppo和vivo都有单独的一款系统软件管家,只有在那个app里才能进行权限设置,所以这种情况下,不应该跳转到系统的设置页面,而是打开软件管家。那么想要去打开一个app就必须要知道这个app的包名。所有,只能通过adb来获取它们各自管家的包名。例如,打开vivo的 i管家,在Terminal中通过执行这个指令 adb shell dumpsys activity top来捕捉软件的主Activity。

adb结果:
vivo的软件管家包名:com.iqoo.secure
oppo的软件管家包名:com.oppo.safe

所以,我那段代码也需要加点判断,代码如下:

    /**     * 跳转到权限设置界面     */    private void getAppDetailSettingIntent(Context context){        // vivo 点击设置图标>加速白名单>我的app        //      点击软件管理>软件管理权限>软件>我的app>信任该软件        Intent appIntent = context.getPackageManager().getLaunchIntentForPackage("com.iqoo.secure");        if(appIntent != null){            context.startActivity(appIntent);            floatingView = new SettingFloatingView(this, "SETTING", getApplication(), 0);            floatingView.createFloatingView();            return;        }        // oppo 点击设置图标>应用权限管理>按应用程序管理>我的app>我信任该应用        //      点击权限隐私>自启动管理>我的app        appIntent = context.getPackageManager().getLaunchIntentForPackage("com.oppo.safe");        if(appIntent != null){            context.startActivity(appIntent);            floatingView = new SettingFloatingView(this, "SETTING", getApplication(), 1);            floatingView.createFloatingView();            return;        }        Intent intent = new Intent();        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        if(Build.VERSION.SDK_INT >= 9){            intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");            intent.setData(Uri.fromParts("package", getPackageName(), null));        } else if(Build.VERSION.SDK_INT <= 8){            intent.setAction(Intent.ACTION_VIEW);            intent.setClassName("com.android.settings","com.android.settings.InstalledAppDetails");            intent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());        }        startActivity(intent);    }

还有酷派、魅族、HTC等等公司里没有机型,还不知道结果是怎么样的,如果有现成手机的,可以测一下分享一下,谢谢 •_^

原文地址;http://blog.csdn.net/perarther/article/details/54025042

更多相关文章

  1. 清理/data/data目录下的本地文件
  2. Invoke-customs are only supported starting with Android(安卓
  3. android相机Camera.Parameters所有的参数值
  4. Xutils3.0使用详解
  5. 2.4 Android中的IPC方式(三)
  6. Android:Installation error: INSTALL_FAILED_INSUFFICIENT_STORA
  7. Android(安卓)查看及设置 SELinux 状态
  8. 通过apk签名使应用程序有系统权限
  9. 修改Android中AVD的目录

随机推荐

  1. android绘制圆角图片
  2. 使用x5cloud云平台来做网络彩讯---------
  3. Android从程序员到架构师之路(高焕堂课件
  4. Android(安卓)Surface Canvas
  5. [Android系统原理及开发要点详解
  6. 剖析andriod联系人(SQLITE3)应用
  7. Android(安卓)API Demo研究(3)
  8. Android(安卓)LifeCycle监控生命周期
  9. android 多个Activity滑动效果
  10. andorid平板中安装完整的ubuntu系统