Identify device by using an unique identifier flutter / android
Asked Answered
O

3

6

My use case is I want to uniquely identify my users devices as I want to provide them subscription and dont want to use any type of login instead use an unique identifier that I can save it on my backend so even if user uninstall or reinstall my app, still be able to access content. Also I've had tried to use androidId (SSAID) but it can change on app signin change or device reset. I am using firebase as backend and flutter on front end.

Oder answered 8/11, 2020 at 0:18 Comment(0)
L
2

You can use the library below in order to find the device's unique ID:

Device ID library

Also this is a duplicate question, so please take care next time to search for the answer prior to asking a question. :)

Lastly, I am not entirely sure of the scope of your project but if you saving user data, sensitive or not on Firebase, logging people in with the devices UID's could be problematic for example in the situation of the user losing their phone they would not be able to recover their lost data. Like I said I'm not sure the scope of your project but just something to think about.

Please let me know if you need any further help!

Leeuwenhoek answered 8/11, 2020 at 0:32 Comment(6)
Hey thanks for your quick response but as I mentioned I've already tried using this device_info (SSAID) but it changed 2 3 new builds so I cannot use this further, secondly I'm not using users sensitive information so user do not need to worry about it, if you can suggest any other ways to achieve this let me knowOder
Please check out the duplicate question I put in my answer as there are a few others ways and libraries of doing it. I am also just curious as to why you even have a database on the cloud if you are not concerned whether the users data is lost or not, why not use a local database?Leeuwenhoek
Didn't seem to find your answer, can you please refer it here and I'm using firebase because I'm providing access to premium content in my app as the user purchases the plan, the plan amount, content all are fetched from db as well as I'm using it for push notificationOder
And I'm wondering I had a build of my app 3 months ago and it's giving me different ssaid as compared to the build I made yesterday and fun fact I didnt even reset my phone also and tried checking from my friend's device got the same result as mine (showing different ssaid)Oder
I reviewed the answer I was looking at and it seems that the library is discontinued so maybe try this library as well as look at dart packages.I would suggest from what I can see using the devices UID's without a backups such a email and password sign in is rather risky and assuming you are storing the UID's in the database directly a hacker could potentially steal all of those UID's unless salted and its possible to get other users device ID's. Look, go with what you think is right, but thats just my view.Leeuwenhoek
yes I've taken email and attached to every uuid but if I roll out an update the new build, the uuid is not similar as previous one as it should be, so I've to ask the user for there email to give them access also cannot use this uuid as it will change after new releases.Oder
S
1

Answer for 2023

For an Android app (especially one using Firebase already), the Firebase installation ID (FID) is considered by Android to be the best practice for obtaining a unique identifier for the device. Most third-party apps do not fall into the category of apps that can obtain a hardware identifier.

There is one exception:

Leveraging hardware identifiers is acceptable if it's required for carrier-related functionality.

In other words, if your app uses the device's SMS capabilities, is the default dialer, or is a system app, you may be able to obtain a hardware identifier like IMEI. However, this requires user permission to work, and it is a much more intrusive process than simply tapping "Allow" on a permissions message like when an app wants to send notifications. AFAIK, they would have to replace their dialer or SMS app with yours. If your app is not something that provides SMS capability in a way that is competitive with other dialers or SMS apps, you might want to consider using an alternative method of user identification, such as an in-app purchase or Google account linking.

Superfluid answered 5/12, 2023 at 19:31 Comment(0)
E
0

This is how to get unique identifier for the device:

For Android using the unique_identifier library to get the IMEI:

// Add this dependency to pubspec.yaml
dev_dependencies:
  unique_identifier: ^0.0.3

// code snippet to get the IMEI 
String  identifier = await UniqueIdentifier.serial;

For IOS, Apple no longer allows you to retrieve the IMEI but you can generate UDID similar to the IMEI:

import 'package:device_info/device_info.dart';

final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
   var data = await deviceInfoPlugin.iosInfo;
   identifier = data.identifierForVendor;
Expropriate answered 8/11, 2020 at 1:45 Comment(5)
Does it change overtime or when device reset? Also does it change in lifetime ? or is it doesnot changeOder
No, IMEI number does not change after factory reset. Since the IMEI number is a part of the hardware, therefore, any reset that is software-based will not be able to change the IMEI of your phone.Expropriate
Crate, please don't forget to mark the correct answer for future to see. :)Leeuwenhoek
okay seems fair, but as I searched about if I've dual sim phone, I would be getting 2 IMEI'sOder
I'll get back to this post after I try these solution. Glad you guys helped !!Oder

© 2022 - 2024 — McMap. All rights reserved.