美文网首页
Android获取手机虚拟机的类型

Android获取手机虚拟机的类型

作者: zivxia | 来源:发表于2022-04-17 21:56 被阅读0次
        private String getCurrentRuntimeValue() {
            String SELECT_RUNTIME_PROPERTY = "persist.sys.dalvik.vm.lib";
            String LIB_DALVIK = "libdvm.so";
            String LIB_ART = "libart.so";
            String LIB_ART_D = "libartd.so";
            try {
                Class<?> systemProperties = Class.forName("android.os.SystemProperties");
                try {
                    Method get = systemProperties.getMethod("get",
                            String.class, String.class);
                    if (get == null) {
                        return "未获取到";
                    }
                    try {
                        final String value = (String) get.invoke(
                                systemProperties, SELECT_RUNTIME_PROPERTY,
                                /* Assuming default is */"Dalvik");
                        if (LIB_DALVIK.equals(value)) {
                            return "Dalvik";
                        } else if (LIB_ART.equals(value)) {
                            return "ART";
                        } else if (LIB_ART_D.equals(value)) {
                            return "ART debug build";
                        }
    
                        return value;
                    } catch (IllegalAccessException e) {
                        return "IllegalAccessException";
                    } catch (IllegalArgumentException e) {
                        return "IllegalArgumentException";
                    } catch (InvocationTargetException e) {
                        return "InvocationTargetException";
                    }
                } catch (NoSuchMethodException e) {
                    return "SystemProperties.get(String key, String def) method is not found";
                }
            } catch (ClassNotFoundException e) {
                return "SystemProperties class is not found";
            }
        }
    

    相关文章

      网友评论

          本文标题:Android获取手机虚拟机的类型

          本文链接:https://www.haomeiwen.com/subject/uvfrertx.html