uuid - Unique Id for my android app -
i want create unique id android app server can identify device request has come , send messages app accordingly. read android_id not safe use unique identifier can compromised on rooted device. , manufacturer don't provide it.
is uuid safe use porpose ? globally unique id app ? if yes, planning store using keystore can keep until app uninstalls. right approach. please suggest.
its safe use uuid, helper function created uuid myself,keep in helper.java , call :
helper.getdeviceid(context);
also don forget change string sharedprefdbname variable sharef db name, can store uuid in db or local file incase app uninstalled said.
//uuid static string deviceid; static string sharedprefdbname = "myappdb"; /** * getdeviceid * @param context * @return string */ public static string getdeviceid(context context){ //lets device id if not available, create , save //means device id created once //if deviceid not null, return if(deviceid != null){ return deviceid; }//end //shared preferences sharedpreferences sharedpref = context.getsharedpreferences(sharedprefdbname,context.mode_private); //lets device id deviceid = sharedpref.getstring("device_id",null); //if saved device id null, lets create , save if(deviceid == null) { //generate new device id deviceid = generateuniqueid(); //shared preference editor sharedpreferences.editor sharedprefeditor = sharedpref.edit(); //save device id sharedprefeditor.putstring("device_id",deviceid); //commit sharedprefeditor.commit(); }//end if device id null //return return deviceid; }//end device id /** * generateuniqueid - generate device id * @return */ public static string generateuniqueid() { string id = uuid.randomuuid().tostring(); return id; }//end method
Comments
Post a Comment