Get the phone chip number

Asked

Viewed 1,191 times

1

I’d like to return the cell phone chip number.

TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
String number = telephonyManager.getLine1Number();
Toast.makeText(this, "Número: " + number, Toast.LENGTH_LONG).show();

I’m using android version 8 and 5 for testing, in version 5 shows nothing returns only the Toast with the String Number and version 8 of it closes the app.

I put that code in the onCreate.

In Logcat shows this message:

No Logcat ele deu essa mensagem: Caused by: java.lang.SecurityException: getLine1NumberForDisplay: Neither user 10083 nor current process hasandroid.permission.READ_PHONE_STATE, android.permission.READ_SMS, or android.permission.READ_PHONE_NUMBERS

Someone helps.

1 answer

0


To use You need the permissions of READ_PHONE_STATE, READ_SMS, READ_PHONE_NUMBERS

getLine1Number()

  • I put these permissions on 'Androidmanifest.xml' but it’s still the same thing.

  • Permissions have to be given at runtime. Even if they are in the Manifest. For testing purposes, you can access the app’s settings screen and provide permissions manually. But the idea is that the app shows that popup to the user

  • https://scache.vzw.com/kb/images/common/google_permissions.jpg you can give permission here

  • I gave the manual permissions in the available ones, Contacts, SMS and Phone now in version 8 not error shows only the blank Toast.

  • Does anything appear in Logcat? Puts the Logcat output in your question. I think it might help

  • No Logcat ele deu essa mensagem: Caused by: java.lang.SecurityException: getLine1NumberForDisplay: Neither user 10083 nor current process hasandroid.permission.READ_PHONE_STATE, android.permission.READ_SMS, or android.permission.READ_PHONE_NUMBERS

  • Well that’s it. Permission

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.