13

In app I want to get unique phone id via TelephonyManager.getDeviceId(). To use this I need this permission READ_PHONE_STATE. Problem is with runtime permission on Android 6. In runtime permission popup dialogue, it asks to grant permission "To make and manage phone calls" which can scary users from using app. What can be done? Or can I get any other unique identifier for device without using such big permission?

TelephonyManager TM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

String deviceId = TM.getDeviceId();
Rafael
  • 6,091
  • 5
  • 54
  • 79
  • 2
    you can set "targetSdkVersion 22" it will runnning in android 6.and it will not showing popup for ask runtime permissions.it will be automatically grant access. :) – RushDroid Mar 10 '16 at 05:56
  • Why do you want to use `TelephonyManager.getDeviceId()`? There are much better [identifiers on Android](https://plus.google.com/+AndroidDevelopers/posts/DMshVTyzqcL) in most cases. – ianhanniballake Mar 10 '16 at 06:04
  • you can refer this [answer](http://stackoverflow.com/a/16869491/2801822) to find unique id. – Chirag Chavda Mar 10 '16 at 06:06
  • I am facing the same issue in my app. In my app, I have to read IMEI. – W.M. Jul 08 '16 at 10:54

1 Answers1

9

I am using this as a unique device identifier in my app and i don't need any run time permission.

String android_id = Settings.Secure.getString(getApplicationContext().getContentResolver(),
                Settings.Secure.ANDROID_ID);

or You can use this

 String uuid = UUID.randomUUID().toString();
Developine
  • 12,483
  • 8
  • 38
  • 42
  • 3
    Informative, but still core question above is not answered yet. Why `READ_PHONE_STATE` leads to a dialogue text reading **"To make and manage phone calls"** – W.M. Jul 08 '16 at 10:57
  • 2
    since using READ_PHONE_STATE, you can handle incoming and outgoing calls and many other things, so it say make and manage phone calls. but question was how to get unique id for device without using READ_PHONE_STATE permission. he asked for another way. – Developine Jul 09 '16 at 17:44
  • This way the user can delete the android_id and generate a new one. Then he could abuse that for Promo-Code abusage. The only way to get an Id which can not be delete is the way Rafael does that. And for that he needs the permission and the problem is the wrong Dialog from Android for that purpose. Of course people will decline that permission, cause they fear being called. So this is not the solution, but rather makes abusage possible. – Adam Ri Jul 27 '18 at 17:10