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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With