0

有没有办法在 Gaia 层检测到 Firefox OS 设备的 pc usb 连接(不是通过充电器)?

Gaia 层中的任何回调也适用于我。

我这样做的原因是,一旦设备通过 USB 连接到 PC,我需要处理一些事件。但是,到目前为止,我还没有找到任何关于它的线索。

4

1 回答 1

1

经过认证的应用程序可能有更好的方法来执行此操作,但对于特权应用程序,一种方法可能是在 sdcard 上使用更改侦听器 - 这仅在设置中启用了 USB 存储选项时才有效。

var sdcard = navigator.getDeviceStorage('sdcard');

sdcard.addEventListener("change", function (event) {
  var reason = event.reason;
  //if reason is "shared" you know you are connected
  //if reason is "available" you know you are not connected
});

确保将设备存储权限添加到清单

"device-storage:sdcard": {
  "access": "readwrite" //could be read only
}
于 2013-12-09T18:46:29.833 回答