Recently upgraded the MIUI system, the new system, the Bluetooth function can not be used, analysis of the reason after the discovery is due to not open the location rights, but can not get the correct value of the location permission is opened, whether it is authorized, all returned to the authorization, so can not judge,
So for Xiaomi mobile phone added some special treatment, just use the following judgment.
Mariotaku
Links: https://www.zhihu.com/question/22102139/answer/24834510
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Detection MIUI
Import java.io.IOException;
Public final class Miuiutils {
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";
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;
}
}
}
Detection FlyMe
Import Android.os.Build;
Import Java.lang.reflect.Method;
Public final class Flymeutils {
public static Boolean Isflyme () {
try {
Invoke Build.hassmartbar ()
Final method = Build.class.getMethod ("Hassmartbar");
return Method! = NULL;
} catch (Final Exception e) {
return false;
}
}
}
The tool class referenced to
Import android.os.Environment;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.IOException;
Import java.util.Collection;
Import java.util.Enumeration;
Import Java.util.Map.Entry;
Import java.util.Properties;
Import Java.util.Set;
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<entry<object, Object>> 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<object> keys () {
return Properties.keys ();
}
Public set<object> KeySet () {
return Properties.keyset ();
}
public int size () {
return Properties.size ();
}
Public collection<object> values () {
return Properties.values ();
}
public static Buildproperties newinstance () throws IOException {
return new Buildproperties ();
}
}
Detect if it is a Xiaomi phone