android.os.SystemProperties

想根据型号来做判断,然后找到了使用SystemProperties这个类可以判断机具型号,

String model= SystemProperties.get("ro.product.model");
if(model.equals("xx")) {//判断是否是XX型号
   return true;
}
return false;

在写代码时,发现引用不到这个类,然后找到了这个文章,是可行的:https://blog.csdn.net/yf1252555020/article/details/82148176

然后试了下这个类最高支持的API是25,25之后就引用不了这个类了:

//以下是为了找到android.os.SystemProperties这个隐藏的类
String SDK_DIR = System.getenv("ANDROID_SDK_HOME")
//("TAG", "SDK_DIR = " + SDK_DIR );
if(SDK_DIR == null) {
    Properties props = new Properties()
    props.load(new FileInputStream(project.rootProject.file("local.properties")))
    SDK_DIR = props.get('sdk.dir');
}
dependencies {
    compileOnly files("${SDK_DIR}/platforms/android-25/data/layoutlib.jar")
}

还有种方法可以使用这类,就是直接把这类添加到项目就可以使用了:

猜你喜欢

转载自blog.csdn.net/css33/article/details/84749370