I am trying to check if USB Debugging is turned on or off through NPM/Node. As soon as an android phone is connected to my system and USB Debugging is turned off, then i need to show a prompt to user to enable usb debugging on his phone.
According to my research, every device (Scanner/Phones/USB) connected to my system has a unique GUID which helps me to distinguish which device is connected. Further, i'm not able to fetch the usb debugging details. Please help!
I want this property which is in this link
Code which i have written so far is on the basis of iSerialNumber but i want to distinguish it on the basis of BUS-TYPE GUID.
var usb = require('usb');
usb.on('attach', function(device)
{
var devices = usb.getDeviceList();
var check = devices[0].deviceDescriptor;
if(check.iSerialNumber == '3')
{
console.log("Please enable USB Debugging");
}
else
{
console.log("Connect an Android device");
}
});
Here is the latest code which i have tried, but it works only for Samsung devices:-
var usbDetect = require('usb-detection');
var Promise = require('bluebird');
var adb = require('adbkit');
var client = adb.createClient();
usbDetect.on('add', function(dev) {
setTimeout(checkAndyDevice, 1500);
});
var checkAndyDevice = function(){
client.listDevices()
.then(function(devices) {
return Promise.map(devices, function() {
return devices;
})
})
.then(function(id) {
if((JSON.stringify(id)) == '[]')
{
console.log("Please enable Usb Debugging option from your Android device");
}
})
.catch(function(err) {
console.error('Something went wrong:', err.stack)
});
};