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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With