emilly
emilly

Reputation: 10530

How to get the device id for mobile/desktop?

I have web app on desktop and mobile(IOS/Android devices) along with mobile apps, i need to identify the user per device(if user changing the device that can be fine). I think it can be device_id where device id can be machine_id(if feasible to get), would try to avoid the user agent as browser version keeps on updating. How I can get the unique device id in javascript(Front end) for mobile/desktop and send it in request ?

Upvotes: 1

Views: 2437

Answers (2)

shraddha patel
shraddha patel

Reputation: 778

  /**
 * Get Device ID
 *
 * @param context Activity/Application context
 */
private fun getDeviceId(context: Context): String
{
    return Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)
}

Upvotes: 1

Sergio Marsilli
Sergio Marsilli

Reputation: 171

May be this can help you

function test () {
    if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
  alert("enumerateDevices() not supported.");
  return;
}

// List cameras and microphones.

navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
  devices.forEach(function(device) {
    alert(device.kind + ": " + device.label +
                " id = " + device.deviceId);
  });
})
.catch(function(err) {
  alert(err.name + ": " + err.message);
});
} test();

Upvotes: 0

Related Questions