How to select a library depending on the OS

edited January 2018 in Android Mode

Hi everyone, i'm developing a software that need's to run on windows, linux and android, since i don't want to make a version depending on the OS, i'd like to know if there is a way to automatically use a librarie, e.g. for android i've to use the following line to toggle on the keyboard:

void showSoftKeyboard() {
  android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager) getActivity().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
  imm.showSoftInput(getActivity().getCurrentFocus(), 0);
}

the part "android.vie.in......." doesn't allow me to compile for windows (which makes sense, since it's for android) but i think there is a way to makeit depend on the OS to use it or not. To recognice the OS i would use:

String os=System.getProperty("os.name"), vendor = System.getProperty("java.vendor.url");

where the OS in android reports as "Linux" but in vendor says "www.android.com", so i know wich OS i'm running.

Answers

  • This is probably a bad idea. Just create a different version for Android.

    Note that you can export your core logic as a library, and then share that between different versions which contain the OS-specific stuff.

  • Please format your code. Edit your post (gear on top right side of any of your posts), select your code and hit ctrl+o. Leave an empty line above and below your block of code. Details here: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text

    Kf

  • @kfrajer Thanks for the advise.

    @KevinWorkman the above was, in part, an example. The software will be running on a Raspberry, with a webcam attached, so i have troubles with the camera libraries (i've found some that works fine with raspbian and others with windows), since i will not distribute the software my self, the software needs to dinamically load a librarie depending on the os

  • What system are you actually deploying to? Android uses a completely different deployment strategy than desktop operating systems, so you can't really use a one-size-fits-all solution.

    I explored this concept in a Processing tool I created called JarMatey. It was designed to detect which OS you're on and deploy the proper libraries. You can see how I did it here.

    But that will only work on desktop Java. If you're targeting Android, then this won't work.

  • @KevinWorkman Thanks, i thought that there was a way to doit

Sign In or Register to comment.