/**
* Prepares the unique UUID for this app installation. This actually means making UUID for the first time and saving this. The next time the UUID will be loaded from preferences.
*/
private void prepareUUID(){
SharedPreferences pref=mContext.getSharedPreferences(PREF_TAG,Activity.MODE_PRIVATE);
mUUID=pref.getString(PREF_UUID,"");
if (mUUID.length() > 0) {
return;
}
mUUID=UUID.randomUUID().toString();
;
SharedPreferences.Editor editor=pref.edit();
editor.putString(PREF_UUID,mUUID);
editor.commit();
}

Example 48

From project behemoth, under directory /core/src/main/java/com/digitalpebble/behemoth/util/.