Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify an Android device programmatically? [duplicate]

Currently, I am using MAC address as the identifier for an Android device.

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String mac = wInfo.getMacAddress();

However, I found the mac is empty for some users' devices. I am a little confused why it could be empty.

If you could figure out the reason, that's the best!

Otherwise, could you provide an alternative for identifying an Android device?

like image 544
JackWM Avatar asked Feb 15 '13 17:02

JackWM


People also ask

How do I identify an Android phone uniquely?

UUID. randomUUID() method generates an unique identifier for a specific installation. You have just to store that value and your user will be identified at the next launch of your application. If you only target smartphones, you can take profit of the fact that the device have telephony services.

How do I find the UUID on my Android phone?

There is no inbuilt UUID. You have Android ID generated at first boot, as suggested by Mudassir, or you have IMEI which is unique ID of your GSM device provided by manufacturer.

What is device UUID Android?

A class that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value. There exist different variants of these global identifiers.

How do I find the unique device ID?

Settings. Secure#ANDROID_ID returns the Android ID as an unique for each user 64-bit hex string. It's known to be null sometimes, it's documented as "can change upon factory reset". Use at your own risk, and it can be easily changed on a rooted phone.


1 Answers

You can identify any android mobile uniquely on basis of imei.

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();

Add the permission into your AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

In emulator, you'll probably get a like a 0000... value. Check it on device to get device id.

like image 56
Ajay S Avatar answered Oct 26 '22 09:10

Ajay S