Last active
December 25, 2015 05:09
-
-
Save sakurabird/6922497 to your computer and use it in GitHub Desktop.
(android)UUIDの取得
This file contains hidden or 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
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