Skip to content

Instantly share code, notes, and snippets.

@jasminsuljic
Last active November 17, 2016 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasminsuljic/6d5429a9e4688255036ab7f7a9049185 to your computer and use it in GitHub Desktop.
Save jasminsuljic/6d5429a9e4688255036ab7f7a9049185 to your computer and use it in GitHub Desktop.
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