14

I want to get the Build.getSerial() from the Android phone. Up to Android O i needed the Manifest.permission.READ_PHONE_STATE permission. However in Android 10 i get the above exception. What i did is added this permission to the manifest

<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
        tools:ignore="ProtectedPermissions"/>

And in the activity i need to request for the permission but there is not such a permission

ActivityCompat.requestPermissions(this@ListActivity, 
   arrayOf(Manifest.permission.READ_PHONE_STATE, 
   <<Manifest.permission.READ_PRIVILEGED_PHONE_STATE>>), 
   SERIAL_NUMBER_PERMISSION)

So how can i get the serial Number if i cannot Grant the permission..? What should i do?

james04
  • 1,580
  • 2
  • 20
  • 46

2 Answers2

9

Refer the documentation here:

Caution: Third-party apps installed from the Google Play Store cannot declare privileged permissions.

As such only google apps and phone manufacturer apps (or if you are device admin or owner app) can access previleged permissions

0

if you just need a unique ID, and don't mind it's unique for devices, users, and APK keys, just use

android.provider.Settings.Secure.getString(getApplicationContext().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
Phlip
  • 5,253
  • 5
  • 32
  • 48
  • I want it to be unique for each device – james04 Mar 03 '22 at 12:25
  • the scuttlebutt is that the ID you get from `adb devices -l` is "insecure," so you are not allowed from inside the app to see it. El Goog has no fix for this, such as a token with one-way encryption – Phlip Mar 03 '22 at 20:31