在Android中获取运行时没有带来正确的运行时

时间:2016-01-25 21:20:09

标签: android android-runtime

我试图在我的设备中获取运行时,我已经在2个设备中测试了以下方法,Xperia Z1,Note 4。

我尝试过以下代码:

private String getIsArtInUse() {
return System.getProperty("java.vm.version");
}

此代码返回2.1,正如一些stackoverflow答案所说,版本大于2.0意味着它的ART,但我的运行时是Dalvik。

private CharSequence getCurrentRuntimeValue() {
private static final String SELECT_RUNTIME_PROPERTY = "persist.sys.dalvik.vm.lib";
private static final String LIB_DALVIK = "libdvm.so";
private static final String LIB_ART = "libart.so";
private static final 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 "WTF?!";
            }
        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";
    }
}

此代码始终返回Dalvik。

public String getRuntime()
{ 
return System.getProperty("java.vm.name");
}

以下内容也会返回Dalvik,但我不认为它会返回确切的应用运行时。

有什么建议吗?

0 个答案:

没有答案