Last active
November 17, 2016 18:37
-
-
Save jasminsuljic/6d5429a9e4688255036ab7f7a9049185 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Utils { | |
private static final String UNIQUE_DEVICE_ID = "unique_device_id"; | |
private static String issuedId; | |
public static String getDeviceID(Context context) { | |
if (issuedId != null) { | |
return issuedId; | |
} | |
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); | |
String id = sharedPreferences.getString(UNIQUE_DEVICE_ID, null); | |
if (id == null) { | |
id = UUID.randomUUID().toString(); | |
Utils.issuedId = id; | |
sharedPreferences.edit().putString(UNIQUE_DEVICE_ID, id) | |
.apply(); | |
} else if (issuedId != null) { | |
return issuedId; | |
} | |
return id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment