Reputation: 1
So for my flutter app I need to get the device (real) serial number for device identification reason for my app feature. Android id didn't suffice because if the device get factory reset, it will change and I don't want that. So how do I get the real serial number so even when the device get factory reset it's still the same. Also I don't care if the device need some kind of configuration because it's for internal use anyway. And the device I use is Infinix HOT 12 Play NFC if that relevant.
This is my AndroidManifest.xml
file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.e_ktp_reader">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"
/>
<application
android:label="Sam Online"
android:name="${applicationName}"
android:icon="@mipmap/launcher_icon">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
I've added READ_PRIVILEGED_PHONE_STATE
permission according to Android Documentation from android documentation that my flutter package refers to and also with below code in dart:
import 'package:device_info_plus/device_info_plus.dart';
// ... more imports
static final DeviceInfoPlugin _deviceInfo = DeviceInfoPlugin();
// ... more code
static Future<String> getSerialNumber() async {
if (Platform.isAndroid) {
return (await _deviceInfo.androidInfo).serialNumber;
}
throw PlatformException(
code: "UNSUPPORTED",
message: "Platform is not supported.",
);
}
That code called getSerialNumber function from device_info_plus package and still return unknown
.
So please help me, what should I do step by step so I can't get serial number in my flutter app from my own android device. Don't care if it needs additional configuration for the device.
Upvotes: 0
Views: 288
Reputation: 44056
For privacy reasons (and to comply with privacy laws in various regions), vendors are making it impossible to get unique device IDs. Your alternative is to make a UUID and write it into local storage.
Upvotes: 0