Skip to content

Instantly share code, notes, and snippets.

@sakurabird
Last active December 25, 2015 05:09
Show Gist options
  • Save sakurabird/6922497 to your computer and use it in GitHub Desktop.
Save sakurabird/6922497 to your computer and use it in GitHub Desktop.
(android)UUIDの取得
private static String uniqueID = null;
private static final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";
public synchronized static String id(Context context) {
if (uniqueID == null) {
SharedPreferences sp = context.getSharedPreferences(PREF_UNIQUE_ID,
Context.MODE_PRIVATE);
uniqueID = sp.getString(PREF_UNIQUE_ID, null);
if (uniqueID == null) {
uniqueID = UUID.randomUUID().toString();
Editor editor = sp.edit();
editor.putString(PREF_UNIQUE_ID, uniqueID);
editor.commit();
}
}
return uniqueID;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment