The way to detect usb connection via pc

355 views Asked by At

Is there anyway to detect pc usb connection (not through charger) to Firefox OS device at Gaia layer?

Any callback in Gaia layer also works for me.

The reason I do this because I need to handle some events once the device connects to pc through USB. However, so far I did not find any clue about it.

1

There are 1 answers

4
Jason Weathersby On BEST ANSWER

Certified apps probably have a better way to do this but for a privileged app one approach may be to use a change listener on the sdcard - This will only work if the USB storage option has been enabled in settings.

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
});

Make sure to add the device storage permission to the manifest

"device-storage:sdcard": {
  "access": "readwrite" //could be read only
}