Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

I have an app that runs on several mobile devices running either Fedora or Android. To consolidate my codebase and distribution I would like to determine which OS I am on. I tried System.getProperty("os.name"), but that just returns "Linux". Is there something unique to Android in the System properties? Thanks

like image 447
Tim OMalley Avatar asked Dec 23 '10 14:12

Tim OMalley


People also ask

How do I find duplicate apps?

Open the Settings app. Scroll down, tap Utilities, and tap Parallel Apps. You'll see a list of apps that you can make copies of—not every app is supported. Find the app you want to clone, and turn its toggle to the On position.


2 Answers

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); } 
like image 135
Herr K Avatar answered Sep 25 '22 06:09

Herr K


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;     } } 
like image 43
AlexR Avatar answered Sep 22 '22 06:09

AlexR