persistent_device_id 1.0.0
persistent_device_id: ^1.0.0 copied to clipboard
A Flutter plugin that provides a persistent device ID using Android Keystore and iOS Keychain.
π± persistent_device_id #
A Flutter plugin that provides a unique, persistent, and secure device identifier on Androidβeven after uninstalling and reinstalling the app.
β¨ Features #
- π Generates a unique ID per device
- β»οΈ Persists across app reinstalls (on Android API β₯ 18 with MediaDrm)
- π§± Securely stored using Android Keystore + EncryptedSharedPreferences
- π« No runtime permissions required
- π¦ Simple, asynchronous API
π¦ Installation #
Add this to your pubspec.yaml:
dependencies:
persistent_device_id: <version>
Then run:
flutter pub get
π οΈ Usage #
Import the package #
import 'package:persistent_device_id/persistent_device_id.dart';
Get the device ID #
final deviceId = await PersistentDeviceId.getDeviceId();
print("Device ID: $deviceId");
βοΈ Supported Platforms #
| Platform | Support |
|---|---|
| Android | β Yes |
| iOS | π§ Not yet (coming soon) |
π§ How It Works #
-
On Android (API β₯ 18), the plugin attempts to use
MediaDrmto derive a hardware-based identifier. -
If
MediaDrmis unavailable or fails (e.g. on rooted devices), a fallback UUID is generated once and securely stored using:
β Android Requirements #
- minSdkVersion: 21
- compileSdkVersion: 34
- No permissions required
π§ Limitations #
MediaDrmis only available on Android API 18 (Jelly Bean 4.3) and above.- On some rooted or modified devices,
MediaDrmmay fail or behave inconsistently. - iOS support is currently not available.
π Example #
Clone the repository and run the example app:
cd example
flutter run
π License #
MIT License. Β© 2025 Mael Toukap.
πββοΈ Contributing #
Contributions are welcome! Please open an issue or submit a pull request on GitHub.