安卓(Android) 怎么返回当前运行时TAGK-DALVIK、TAGARART、TAGJARTARDUPDGGUBUD的名称

2019年10月13日15:11:20安卓(Android) 怎么返回当前运行时TAGK-DALVIK、TAGARART、TAGJARTARDUPDGGUBUD的名称已关闭评论 320 1286字阅读4分17秒

1.简介

安卓(Android) 怎么返回当前运行时TAGK-DALVIK、TAGARART、TAGJARTARDUPDGGUBUD的名称?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    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";
    private static final String TAG_UNKNOWN = "Unknown";
    private static final String TAG_DALVIK = "Dalvik";
    private static final String TAG_ART = "ART";
    private static final String TAG_ART_DEBUG_BUILD = "ART debug build";

    
     
    private static final String getCurrentRuntimeValue() {
        try {
            Class<?> systemProperties = Class
                    .forName("android.os.SystemProperties");
            try {
                Method get = systemProperties.getMethod("get",
                        String.class, String.class);
                if (get == null) {
                    
                    return TAG_UNKNOWN;
                }
                try {
                    final String value = (String) get.invoke(
                            systemProperties, SELECT_RUNTIME_PROPERTY, 
                            "Dalvik");
                    if (LIB_DALVIK.equals(value)) {
                        return TAG_DALVIK;
                    } else if (LIB_ART.equals(value)) {
                        return TAG_ART;
                    } else if (LIB_ART_D.equals(value)) {
                        return TAG_ART_DEBUG_BUILD;
                    }

                    return value;
                } catch (IllegalAccessException e) {
                    
                } catch (IllegalArgumentException e) {
                    
                } catch (InvocationTargetException e) {
                    
                }
            } catch (NoSuchMethodException e) {
                
            }
        } catch (ClassNotFoundException e) {
            
        }

        return TAG_UNKNOWN;
    }
}

 
继续阅读