android 权限管理界面设计,Android应用开发之Android 6.0以上权限拒绝打开权限设置界面的解决方法...

本文将带你了解Android应用开发Android 6.0以上权限拒绝打开权限设置界面的解决方法,希望本文对大家学Android有所帮助。

本人使用小米手机,打开qq或者微信的时候,某个权限拒绝的话,会提示你开启,点击开启会跳转到app的权限设置界面,当然了,这是国内系统深层定制的原因,也就是说这个界面原声的android没有的!这里以小米和魅族作为示例讲解如何让用户手动打开权限,当然了如果是原声的android就让他跳转到应用的详情设置页面(有点坑,因为普通用户还是不知道怎么整)。

参考了很多零零碎碎的东西,网址已经找不到了。。。。。。

ok,第一步是跳转到系统的界面,下面基本上可以从9开始考虑了,可以简化。

String SCHEME = "package";

//调用系统InstalledAppDetails界面所需的Extra名称(用于Android   2.1及之前版本)

final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName";

//调用系统InstalledAppDetails界面所需的Extra名称(用于Android   2.2)

final String APP_PKG_NAME_22 = "pkg";

//InstalledAppDetails所在包名

final String APP_DETAILS_PACKAGE_NAME = "com.android.settings";

//InstalledAppDetails类名

final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails";

Intent intent = new Intent();

final int apiLevel =   Build.VERSION.SDK_INT;

if (apiLevel >= 9) {   // 2.3(ApiLevel   9)以上,使用SDK提供的接口

intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);

Uri uri = Uri.fromParts(SCHEME,   getPackageName(), null);

intent.setData(uri);

} else {   //   2.3以下,使用非公开的接口(查看InstalledAppDetails源码)

//   2.2和2.1中,InstalledAppDetails使用的APP_PKG_NAME不同。

final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22

:   APP_PKG_NAME_21);

intent.setAction(Intent.ACTION_VIEW);

intent.setClassName(APP_DETAILS_PACKAGE_NAME,

APP_DETAILS_CLASS_NAME);

intent.putExtra(appPkgName,   getPackageName());

}

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

第二个,miui,首先你得判断是miui,亲自测试,MIUI7稳定版,MIUI8开发板本可行,工具类下面会提供下载

if (CheckPhoneSystemUtils.isMIUI())   {

MLog.i("产品/硬件的制造商小米:");

intent.setAction("miui.intent.action.APP_PERM_EDITOR");

intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");

intent.putExtra("extra_pkgname",   getPackageName());

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

try {

startActivity(intent);

} catch (Exception   e) {

e.printStackTrace();

Toast.makeText(MediaRecoderService.this, "只有MIUI才可以设置哦", Toast.LENGTH_SHORT).show();

}

}

第三个,flyme(由于没有flyme机子),采用的云手机测试的

else if (CheckPhoneSystemUtils.isFlyme())   {

intent.setAction("com.meizu.safe.security.SHOW_APPSEC");

intent.addCategory(Intent.CATEGORY_DEFAULT);

intent.putExtra("packageName", getPackageName());

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

try {

startActivity(intent);

} catch (Exception   e) {

e.printStackTrace();

Toast.makeText(MediaRecoderService.this, "只有Flyme才可以设置哦", Toast.LENGTH_SHORT).show();

}

}

下面是工具类:BuildProperties

public class BuildProperties {

private final Properties properties;

private BuildProperties() throws IOException   {

properties = new Properties();

properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));

}

public boolean containsKey(final Object key) {

return properties.containsKey(key);

}

public boolean containsValue(final Object value) {

return properties.containsValue(value);

}

public Set>   entrySet() {

return properties.entrySet();

}

public String getProperty(final String name) {

return properties.getProperty(name);

}

public String getProperty(final String name, final String defaultValue) {

return properties.getProperty(name,   defaultValue);

}

public boolean   isEmpty()   {

return properties.isEmpty();

}

public Enumeration keys()   {

return properties.keys();

}

public   Set keySet()   {

return properties.keySet();

}

public int size() {

return properties.size();

}

public Collection values()   {

return properties.values();

}

public static BuildProperties newInstance() throws IOException {

return new BuildProperties();

}

CheckPhoneSystemUtils

private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";

private static   final String KEY_MIUI_VERSION_NAME =   "ro.miui.ui.version.name";

private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";

/**

* 检测MIUI

*

*   @return

*/

public static boolean   isMIUI()   {

try {

final BuildProperties prop =   BuildProperties.newInstance();

return prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null || prop.getProperty(KEY_MIUI_VERSION_NAME,   null) != null || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE,   null)   != null;

} catch (final IOException e)   {

return false;

}

}

/**

* 检测Flyme

*

* @return

*/

public static boolean   isFlyme()   {

try {   // Invoke   Build.hasSmartBar()

final Method method = Build.class.getMethod("hasSmartBar");

return method !=

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值