I want to generate android device unique id for my android application to create favourite according to user device udid.
Asked
Active
Viewed 2.9k times
7
-
In case the user uninstalls your app, all data will be removed as well. So you will always have the time when the user installs the app. You can use it as an UID. – Jul 02 '12 at 11:55
3 Answers
19
All devices have a unique id.
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);

Anirudh Ramanathan
- 46,179
- 22
- 132
- 191

Daniel
- 1,537
- 1
- 13
- 16
-
-
5Be aware that while Secure.ANDROID_ID will generate a one-time unique ID when the device is booted the very first time, this ID will be lost should the device ever be reset to its factory defaults. A better solution is to rely upon the device's MAC address, assuming of course the device has Wi-Fi support, which practically all devices these days do. – Johann Nov 05 '12 at 16:19
0
private String uDiD = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);

Petter Friberg
- 21,252
- 9
- 60
- 109

Farruh Habibullaev
- 2,342
- 1
- 26
- 33
0
You can use different values as udid. The above mentioned Secure.ANDROID_ID has some cons It can be null It is same on 2.2 and some 4.2 devices You can use MacAddress of device or IMIE address(Can be null on devices without cellular connection)

Ahsan Idrees
- 11
- 6