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.
You can use the library below in order to find the device's unique ID:
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!
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.
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;
© 2022 - 2024 — McMap. All rights reserved.