Detect if it is a Xiaomi phone

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.