我想允许我的apk在应用程序运行时监视HDMI设备状态。如果屏幕关闭或断开,我希望应用程序将HDMI状态写回到sql数据库。 这是我到目前为止的内容:
/**
* Checks device switch files to see if an HDMI device/MHL device is plugged in, returning true if so.
*/
private boolean isHdmiSwitchSet() {
// The file '/sys/devices/virtual/switch/hdmi/state' holds an int -- if it's 1 then an HDMI device is connected.
// An alternative file to check is '/sys/class/switch/hdmi/state' which exists instead on certain devices.
File switchFile = new File("/sys/devices/virtual/switch/hdmi/state");
if (!switchFile.exists()) {
switchFile = new File("/sys/class/switch/hdmi/state");
}
try {
Scanner switchFileScanner = new Scanner(switchFile);
int switchValue = switchFileScanner.nextInt();
switchFileScanner.close();
return switchValue > 0;
} catch (Exception e) {
return false;
}
}
我将如何将这些值写入远程服务器上的SQL数据库?