How to determine if my app is running on Android [duplicate]

There are several properties you could check. Candidates are:

  • java.vendor.url –> http://www.android.com
  • java.vm.name –> Dalvik (I don’t know, which one Fedora is using…)
  • java.vm.vendor –> The Android Project
  • java.vendor –> The Android Project

Maybe you want to check by yourself?

Properties p = System.getProperties();
Enumeration keys = p.keys();
while(keys.hasMoreElements()) {
   String key = (String) keys.nextElement();
   String value = (String) p.get(key);
   System.out.println(key + " >>>> " + value);
}

I do not know Android but if you do not find some unique system property you can sometimes identify the system if some specific class exists there. So you can do the following:

boolean isAndroid() {
    try {
        Class.forName("the class name");
        return true;
    } catch(ClassNotFoundException e) {
        return false;
    }
}

Leave a Comment