Advertisement
Smile_Studio

HDMISwitch

Oct 16th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. public static boolean isHdmiSwitchSet() {
  2.         // The file '/sys/devices/virtual/switch/hdmi/state' holds an int -- if it's 1 then an HDMI device is connected.
  3.         // An alternative file to check is '/sys/class/switch/hdmi/state' which exists instead on certain devices.
  4.         File switchFile = new File("/sys/devices/virtual/switch/hdmi/state");
  5.         if (!switchFile.exists()) {
  6.             switchFile = new File("/sys/class/switch/hdmi/state");
  7.         }
  8.         try {
  9.             Scanner switchFileScanner = new Scanner(switchFile);
  10.             int switchValue = switchFileScanner.nextInt();
  11.             switchFileScanner.close();
  12.             return switchValue >= 0;
  13.         } catch (Exception e) {
  14.             return false;// always return false in STB Android 6.0.1
  15.         }
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement