如何判断设备是否为鸿蒙系统设备
通过以上代码逻辑,可以准确的判断出当前华为设备是鸿蒙系统还是EMUI版本的Android系统。
·
JAVA代码:
public boolean isHarmony(Context context) {
try {
int id = Resources.getSystem().getIdentifier("config_os_brand", "string", "android");
return context.getString(id).equals("harmony");
} catch (Exception e) {
return false;
}
}
Kotlin代码:
fun isHarmony(context: Context): Boolean {
return runCatching {
val id = context.resources.getIdentifier("config_os_brand", "string", "android")
context.getString(id) == "harmony"
}.getOrDefault(false)
}
通过以上代码逻辑,可以准确的判断出当前华为设备是鸿蒙系统还是EMUI版本的Android系统
更多推荐

所有评论(0)