简体   繁体   中英

is it possible to determine whether the current VM is Java SE or Dalvik?

I wish to implement something looks like this:

if(isJavaVirtualMachine()){
    System.out.println("You are running on a JVM");
}else if(isDalvikVirtualMachine()){
    Log.i("env","You are running on an android.");
}

Is it possible? If its impossible by Java itself, can I do it by JNI?

Use System.getProperty . The property names for Dalvik are documented here

As ykaganovich pointed out, it should be pretty easy to distinguish between plain Java and Android at runtime. The other problem is that you won't have Android specific classes like Log in a plain Java environment, so you will run into problems at runtime! A possible solution would be to assemble platform specific adapters using reflection, so you pull in the dependencies only at runtime (might be somewhat tricky).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM