0

What is the code to know on which system app is running with JavaFX?

No need to read further it is just to go over the quality standards check.

Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
  • 2
    *What is the code to know on which system app is running with javafx?* what do you mean by `system app` - can you be more specific? Or add some more detail or code that shows what are you trying to achieve. – Shekhar Rai Jan 04 '20 at 14:27
  • Does this answer your question? [How do I programmatically determine operating system in Java?](https://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java) – fuggerjaki61 Jan 04 '20 at 16:38

2 Answers2

1

See the code below that checks whether JavaFX runs on iOS, Android or Desktop.

/******************************************
 * Main Class
 ******************************************/    
 public class CheckPlatform {

   public static void main(String [] args) {

      if(OSPlatform.isIOS())
         System.out.println("This is an Apple Device");
      else if(OSPlatform.isAndroid())
         System.out.println("This is an Android Device");
      else if(OSPlatform.isDesktop())
         System.out.println("This is a Desktop PC");

   } // main()
} // class CheckPlatform


/******************************************
 * OSPlatform Class
 ******************************************/
public class OSPlatform {

   private static String platform;

   static {
      platform = System.getProperty("javafx.platform","desktop").toUpperCase();
   }

   public static boolean isAndroid() {
      return platform.equals("ANDROID");
   } // isAndroid()

   public static boolean isDesktop() {
      return platform.equals("DESKTOP");
   } // isDesktop()

   public static boolean isIOS() {
      return platform.equals("IOS");
   } // isIOS()
} // class OSPlatform
javasuns
  • 1,061
  • 2
  • 11
  • 22
1

The class com.sun.javafx.PlatformUtil contains all the methods you need to check the running OS. It's not recommended to use sun classes in some cases but here are some of the public static methods the utility class provides:

  • public static boolean isWindows()
  • public static boolean isWinVistaOrLater()
  • public static boolean isWin7OrLater()
  • public static boolean isMac()
  • public static boolean isLinux()
  • public static boolean isSolaris()
  • public static boolean isUnix()
  • public static boolean isEmbedded()
  • public static boolean isIOS()
  • public static boolean isAndroid()
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36