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
}