In general, it is necessary to determine the device type and system version in the development of Android programs.
1, equipment type judgmentFor example, the judgment belongs to Google Nexus 5,nexus 7,MIUI V5, MIUI V6, Samsung devices, Meizu devices, etc. This type of problem is used by Android.os.Build.MODEL to judge that Android.os.Build.MODEL is a string variable that can determine what device the Android device belongs to based on some special fields in the string, such as determining the Nexus 7, code into public static Boolean isN7 () {
Return "Nexus 7". Equals (Android.os.Build.MODEL);
So usually in the development process if you do not know the model value of a device, write a test program output Android.os.Build.MODEL value, and then use this value in my program to participate in the judgment.
2. System version judgment (API version)For example, the judgment system belongs to 2.3, 3.0, 4.4, 5.0, etc., this attribute is judged using the system's Android.os.Build.VERSION.SDK_INT variable. The most common scenario is the API version used to determine some of the system functions, for example, some methods only have a higher version of the API, the use of the lower version will cause the program to crash. But there is another scenario that leads to a third way to fix the usage scenario: most of the operating systems are open-source, and Google's Android is the default, but don't forget the Meizu flyme OS and Xiaomi Miui, which are variants of Android. If using non-Xiaomi mobile phone also installed MIUI, the latter is non-Meizu mobile phone installed Meizu FlyMe OS, this situation how to judge it. Take Meizu: Obviously this time can not be used to determine the type of device, because the non-Meizu device installed Meizu system. So this time can only judge this operating system is Meizu FlyMe OS, its operating system should have some of its own features, so as long as you find a unique feature can solve the above problem.
3, Judge the special operating system---Get the system properties to study (Meizu as an example)Enter the ADB shell to get the Meizu system properties:
- First enter CMD and enter the ADB shell command into the ADB shell (provided that the ADB must be configured in the system environment variable)
C:\users\administrator>
adb Shell
[Email protected]:/$
- Go to the System directory
[Email protected]:/$
CD System
CD system
[Email Protected]:/system $
- Viewing System Properties
[Email Protected]:/system $
Cat Build.prop
Cat Build.prop
# Begin Build Properties
# Autogenerated by buildinfo.sh
Ro.build.cta=noncta
ro.build.id=ktu84p
Ro.build.mask.id=4.4.4-1423716396_wo
ro.build.args=
ro.build.inside.id=4.4.4-20150212124636
Ro.build.version.incremental=m76. flyme_os_4.2.2.1.20150212124636
Ro.build.version.sdk=19
Ro.build.version.codename=rel
ro.build.version.release=4.4.4 ..... There's a lot more.
- Filter for attributes that contain flyme characters because, since it is a Meizu operating system, the word flyme is most representative of its properties
[Email Protected]:/system $
Cat Build.prop | grep Flyme
Cat Build.prop | grep Flyme
Ro.build.version.incremental=m76. flyme_os_4.2.2.1.20150212124636
Ro.build.display.id=flyme OS 4.2.2.1U
Ro.build.description=meizu_mx4pro-user 4.4.4 ktu84p m76. flyme_os_4.2.2.1.2015021
2124636 Release-keys
Ro.build.fingerprint=meizu/meizu_mx4pro/mx4pro:4.4.4/ktu84p/m76. flyme_os_4.2.2.1
.20150212124636:user/release-keys
[Email Protected]:/system $ Handsome Select to four properties: Ro.build.version.incremental ro.build.display.id ro.build.description Ro.build.fingerprint
- For a different installation of the Meizu OS device, repeat the above steps. Eventually it will be found that the ro.build.display.id attribute can be used as the only feature of a Meizu operating system (since this attribute value will almost contain the FlyMe field, which is exactly what we want). We can use this attribute to distinguish it from other systems.
- The final step, of course, is how to take out this attribute value.
Judge is the Meizu operating system public static Boolean Ismeizuflymeos () {
Return Getmeizuflymeosflag (). toLowerCase (). Contains ("FlyMe");
} /**
* Get Meizu system operation version ID
*/
public static String Getmeizuflymeosflag () {
Return Getsystemproperty ("Ro.build.display.id", "" ");
} private static string Getsystemproperty (string key, string defaultvalue) {
try {
class<?> CLZ = Class.forName ("
android.os.SystemProperties");
Method get = Clz.getmethod ("Get", String.class, String.class);
Return (String) Get.invoke (CLZ, Key, DefaultValue);
} catch (ClassNotFoundException e) {
} catch (Nosuchmethodexception e) {
} catch (Illegalaccessexception e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}
return defaultvalue;
The following are some methods of Xiaomi operating system/**
* Get MIUI version name
*/
public static String Getmiuiversionname () {
Return Getsystemproperty (
"Ro.miui.ui.version.name", null);
}//MIUI V5 version public static Boolean isV5 () {
if ("V5". Equalsignorecase (Getmiuiversionname ())) {
return true;
}
return false;
}
ADB Shell View System properties (used to determine a particular operating system)