I'm creating android app in which user store some data. I want to add an option that two users can synchronize/merge their databases. I want to do this by checking if an ID of element from one database exists in second one. This disclaims using simple INTEGER AUTO INCREMENT
cause in both databases there will be element with ID e.g. 1
which won't mean that those elements are the same. I was thinking about an ID that has some prefix that is unique for every android device and then some number e.g. ABCD000001
where ABCD
is this unique device ID. But the problem is I don't know how to generate this prefix. Do you have any ideas? Also maybe you have better idea than checking ID...
Asked
Active
Viewed 56 times
0
-
1Try adding a prefix with unique identifier. Look at this page: https://developer.android.com/training/articles/user-data-ids.html – Lorenzo Vincenzi Oct 03 '17 at 13:52
1 Answers
0
You can create a prefix using device IMEI
but you will need READ_PHONE_STATE
permission. Also you can use android-id
but it can be null or not unique for some devices.
So I strongly suggest to use this code snippet to create a uuid
that is unique for each device. I have used it and it works fine on different devices.

Akram
- 2,158
- 1
- 17
- 24