手机android版本不符合rom要求,Android 获取手机当前ROM版本信息

如有需要,直接拿去用,不客气

package com.example.getphoneinfodemo;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.Properties;

import android.content.Context;

import android.content.pm.PackageInfo;

import android.content.pm.PackageManager;

import android.os.Environment;

public class GetPhoneInfoUtil {

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_EMUI_VERSION_CODE = "ro.build.hw_emui_api_level";

private static final String KEY_FLYME_ID_FALG_KEY = "ro.build.display.id";

private static final String KEY_FLYME_ICON_FALG = "persist.sys.use.flyme.icon";

private static final String KEY_FLYME_SETUP_FALG = "ro.meizu.setupwizard.flyme";

private static final String KEY_FLYME_PUBLISH_FALG = "ro.flyme.published";

private Properties mProper;

public static GetPhoneInfoUtil mPhoneInfoUtil;

public enum ROM_TYPE {

MIUI_ROM,

FLYME_ROM,

EMUI_ROM,

OTHER_ROM

}

private GetPhoneInfoUtil(){

if(mProper==null){

mProper=new Properties();

}

try {

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

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

};

public static GetPhoneInfoUtil getInstance() {

if(mPhoneInfoUtil==null){

synchronized (GetPhoneInfoUtil.class) {

if(mPhoneInfoUtil==null){

mPhoneInfoUtil=new GetPhoneInfoUtil();

}

}

}

return mPhoneInfoUtil;

}

/**

* 获取手机厂商

* @return

*/

public String getDeviceBrand() {

return android.os.Build.BRAND;

}

/**

* 获取手机型号

*

* @return

*/

public String getPhoneModel() {

return android.os.Build.MODEL;

}

/**

* 获取系统版本号

*

* @return

*/

public String getSystemVersion() {

return android.os.Build.VERSION.RELEASE;

}

/**

* 获取当前应用版本

* @return

*/

public String getVersion(Context context) {

try {

PackageManager manager = context.getPackageManager();

PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);

String version = info.versionName;

return version;

} catch (Exception e) {

e.printStackTrace();

return "";

}

}

/**

* 判断ROM是否为MIUI

* @return

*/

public boolean isMIUI() {

return mProper.containsKey(KEY_MIUI_VERSION_CODE) || mProper.containsKey(KEY_MIUI_VERSION_NAME);

}

/**

* 判断ROM是否为EMUI

* @param name

* @return

*/

public boolean isEMUI() {

return mProper.containsKey(KEY_EMUI_VERSION_CODE);

}

/**

* 判断ROM是否为Flyme

* @return

*/

public boolean isFlyme(){

return mProper.containsKey(KEY_FLYME_ICON_FALG) || mProper.containsKey(KEY_FLYME_SETUP_FALG) || mProper.containsKey(KEY_FLYME_PUBLISH_FALG);

}

/**

* 获取ROM版本信息

* @return

*/

public String getRomInfo(){

if(isMIUI()){

return ROM_TYPE.MIUI_ROM+" "+mProper.getProperty(KEY_MIUI_VERSION_NAME) ;

}else if(isFlyme()){

return ROM_TYPE.FLYME_ROM+" "+mProper.getProperty(KEY_FLYME_ID_FALG_KEY);

}else if(isEMUI()){

return ROM_TYPE.EMUI_ROM+" "+mProper.getProperty(KEY_EMUI_VERSION_CODE);

}else{

return ROM_TYPE.OTHER_ROM+"";

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值