felHR85 / UsbSerial

Usb serial controller for Android
MIT License
1.78k stars 582 forks source link

how to distinguish two same machine connected with android(i tried using serial number but getSerialNumber is returning null)) #298

Open onkarcountrydelight opened 4 years ago

Shreyas-R commented 4 years ago

You can use,

usbDevice.getDeviceID     // Java
usbDevice.deviceID   // Kotlin 

Device ID will always be unique everytime you connect any usb device.

onkarcountrydelight commented 4 years ago

Thanks for your response, but i want an id which is unique for lifetime of machine (deviceId is getting changed after reconnect the device or restart the app)

Shreyas-R commented 4 years ago

As per your question, to differentiate between two similar machines, device ID is sufficient as it will be unique for two same machines.

If you are looking for unique ID for lifetime then you have to either, (a) manually change the serial number of whatever machine you are interfacing with Android which is currently returning null for you (not defined by machine manufacturer). (b) implement some query function within your machine which you have to query when you connect to Android which returns unique ID defined for that machine by you.

Both require you to tinker with your machine. I don't think there is any other way for that.

onkarcountrydelight commented 4 years ago

Thanks, will check that