MLQ
MLQ

Reputation: 13511

Generate persistent application UUID in Android upon app installation

I need to distinguish my app's installations so I generate a UUID in my app via java.util.UUID.randomUUID() then save it as a String in the shared preferences. However, when I go to the phone's Settings, manage the applications, click on my app, and press "Clear Data," the next time my app runs, a new UUID is generated. I believe this is because the previous shared prefs has been deleted.

Is there a way for me to create a UUID that persists for as long as the app is installed, even when "Clear Data" is pressed from the Settings?

Upvotes: 2

Views: 3117

Answers (1)

Royston Pinto
Royston Pinto

Reputation: 6731

Clear Data will clear all the files, databases from your app space. One good way to keep persistent data is to create your own private folder in SD card, create a file that saves this UUID. This again isnt foolproof as user may delete the folders from SD card. You can even create invisible folders or invisible files by procceding the filename with a dot.

Upvotes: 4

Related Questions