Question

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.

Was it helpful?

Solution

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top