Alex Tech Alex Tech - 4 months ago 18x
Android Question

Android no permission to read from phonebook

I'm new on android. I want to make a function that check if I already have a phone number in my phonebook.
I added read contacts permission on my manifest:

<uses-permission android:name="android.permission.READ_CONTACTS" />

I can't get the permission to read the contacts and my app crash every time.


Basically, you have to check if you have a permission or not before you doing something from the dangerous permissions list

int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,

If it returns that your app is not granted then you need to ask for it in the runtime.

            new String[]{Manifest.permission.READ_CONTACTS},

So, put the code above after your first "if" statement in "else" block.

Let me know if you have any more questions.