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.
I put these permissions on 'Androidmanifest.xml' but it’s still the same thing.
– Ari Melo
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
– Messias Lima
https://scache.vzw.com/kb/images/common/google_permissions.jpg you can give permission here
– Messias Lima
I gave the manual permissions in the available ones, Contacts, SMS and Phone now in version 8 not error shows only the blank Toast.
– Ari Melo
Does anything appear in Logcat? Puts the Logcat output in your question. I think it might help
– Messias Lima
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
– Ari Melo
Well that’s it. Permission
– Messias Lima