android 如何检测miui v5,检测Android系统是否是MIUI

package com.imooc.smartbutler;

/*

* 项目名: SmartButler

* 包名: com.imooc.smartbutler

* 文件名: MIUIUtils

* 创建者: Sunny

* 创建时间: 2017/2/2 16:02

* 描述: 检测系统是否为 MIUI

*/

import android.content.ActivityNotFoundException;

import android.content.Context;

import android.content.Intent;

import android.net.Uri;

import android.os.Build;

import android.os.Environment;

import android.provider.Settings;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.Properties;

public class MIUIUtils{

// 检测MIUI

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

*

* @ref https://dev.xiaomi.com/doc/p=254/index.html

* @return

*/

public static boolean isMIUI()

{

String device = Build.MANUFACTURER;

System.out.println("Build.MANUFACTURER = " + device);

if (device.equals("Xiaomi"))

{

System.out.println("this is a xiaomi device");

Properties prop = new Properties();

try

{

prop.load(new FileInputStream(new File(Environment

.getRootDirectory(), "build.prop")));

} catch (IOException e)

{

e.printStackTrace();

return false;

}

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;

} else

{

return false;

}

}

/**

* 跳转到应用权限设置页面 https://www.tuicool.com/articles/jUby6rA

*

* @param context

* 传入app 或者 activity

* context,通过context获取应用packegename,之后通过packegename跳转制定应用

* @return 是否是miui

*/

public static boolean gotoPermissionSettings(Context context)

{

boolean mark = isMIUI();

if (mark)

{

// 只兼容miui v5/v6 的应用权限设置页面,否则的话跳转应用设置页面(权限设置上一级页面)

try

{

Intent localIntent = new Intent(

"miui.intent.action.APP_PERM_EDITOR");

localIntent

.setClassName("com.miui.securitycenter",

"com.miui.permcenter.permissions.AppPermissionsEditorActivity");

localIntent.putExtra("extra_pkgname", context.getPackageName());

context.startActivity(localIntent);

} catch (ActivityNotFoundException e)

{

Intent intent = new Intent(

Settings.ACTION_APPLICATION_DETAILS_SETTINGS);

Uri uri = Uri.fromParts("package", context.getPackageName(),

null);

intent.setData(uri);

context.startActivity(intent);

}

}

return mark;

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值