Identify device by using an unique identifier flutter / android

Viewed 2047

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.

2 Answers

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!

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;
Related