0

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.

Sam
  • 4,521
  • 13
  • 46
  • 81
  • not sure if I understand, but cant you just use `adb devices` to check when a device is connected and go from there? – Aras Dec 09 '13 at 17:37

1 Answers1

1

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
}
Jason Weathersby
  • 1,071
  • 5
  • 5
  • Thanks for the reply. However, my intention is to get the event when the usb connect to PC (not to the charger) . I guess gaia should have a callback to get this event. – Sam Dec 10 '13 at 03:33
  • Without enabling USB storage option, will that be any approach to get pc usb connection event? – Sam Dec 10 '13 at 04:01
  • well, I think this function is not yet implemented yet. – Sam Dec 10 '13 at 09:57
  • I do not see a way to do it in privileged apps. Maybe WebUSB API will make it possible in the future. – Jason Weathersby Dec 10 '13 at 19:00