When I first log in, I want to get and write some native android device code to the Realtime Database Firebase, so that with a single login and password, I can only log in from one device (from which the first login was made). What code and how to get it to distinguish between android devices? I do all this with Java and Real time Database Firebase.
Asked
Active
Viewed 47 times
0
-
1https://stackoverflow.com/questions/1972381/how-to-get-the-devices-imei-esn-programmatically-in-android – couka May 28 '21 at 13:49
-
https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id – MobIT May 28 '21 at 16:51
-
1Does this answer your question? [Is there a unique Android device ID?](https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id) – Gpack May 29 '21 at 10:55
1 Answers
0
You can get an identifier like IMEI and update it in the database this way:
const deviceImei = android.telephony.TelephonyManager.getDeviceId()
public void updateUserDevice(String userId, String identifier) {
User user = new User(name, identifier);
mDatabase.child("users").child(userId).setValue(user);
}
Though using IMEI is not recommended for identification purposes about which you can read more here. Other option would be getting device android ID, which does not require any special permission:
String device_unique_id = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);

Dharmaraj
- 47,845
- 8
- 52
- 84