I\'m working on a simple app that browses through the user\'s contacts. Unfortunately I keep getting the following error:
java.lang.SecurityException: Permission
the <uses-permission>
should be contained in the <manifest>
element. See Structure of the Manifest File. So trying putting it into <application>
or <activity>
, won't work. Desperation move: try to move <uses-sdk>
before <application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Also if you can test without the other permissions, remove them.
EDIT: Can you please check if this is your TOP line in your manifest file:
<?xml version="1.0" encoding="utf-8"?>
None of the above helped. The solution is quite simple. you'll need a runtime permission request.
with or without placing the permission in your manifest, You will need to request that permission from the User on-the-fly.
if( getApplicationContext().checkSelfPermission( Manifest.permission.READ_CONTACTS ) != PackageManager.PERMISSION_GRANTED )
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_CONTACTS}, resultValue);
only then after the approval you will be able to query the contacts phone number/name etc.
Try this in your on create method
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_CONTACTS},1);
I ran into this issue today and none of the above fixes worked for me.
What the issue ended up being had to do with my Eclipse. What I had written in the manifest.xml
and what was in the Permissions
tab weren't the same. I had the READ_CONTACTS
permission in my manifest.xml
, but READ_PROFILE
was in it's place under my permission's tab.
I know this is an old thread, but hopefully if someone has the same issue I did they'll stumble across this.
Thanks!
I had the same problem and none of the solutions I read helped to resolve it until I added the WRITE_EXTERNAL_STORAGE
permission along with the READ_CONTACTS
permission.
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I was totally stuck on this until I read this article about how permissions are handled starting with SDK 23. The critical hint:
If the application's targetSdkVersion is set to less than 23. It will be assumed that application is not tested with new permission system yet and will switch to the same old behavior: user has to accept every single permission at install time and they will be all granted once installed !
I opened up my gradle.build
file and changed targetSdkVersion 23
to targetSdkVersion 22
, and now everything works great! I'll eventually find time to build in the new permissions system and switch back to targetSdkVersion 23
, which is probably the more correct answer. This is a temporary shortcut.