permission.READ_CONTACTS似乎不工作 [英] permission.READ_CONTACTS does not seem to work
问题描述
我工作的一个简单的应用程序,通过用户的联系人浏览。不幸的是我不断收到以下错误:
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 Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/contacts from pid=27455, uid=10171 requires android.permission.READ_CONTACTS
我的清单文件看起来是这样的:
My manifest file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.helloMaps"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MapsActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我想通过看我的联系方式:
I'm trying to look at my contacts by:
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
我已经尝试添加&LT;使用许可权的android:NAME =android.permission.READ_CONTACTS/&GT;
或的android:权限=android.permission.READ_CONTACTS
到&lt;应用&GT;
或&LT;活性GT;
,但都没有成功。
I've tried to add <uses-permission android:name="android.permission.READ_CONTACTS" />
or android:permission="android.permission.READ_CONTACTS"
to <application>
or <activity>
, but both didn't work.
我跑出来的选择,没有任何人知道我在这里失踪?
I'm running out of options, does anybody know what I'm missing here?
推荐答案
的&LT;使用许可权&GT;
应包含在&LT;清单&GT;
元素。见清单文件的结构。因此,试图把它变成&lt;应用&GT;
或&LT;活性GT;
,将无法正常工作。绝望的举动:尝试移动&LT;采用-SDK&GT;
在&lt;应用&GT;
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.
编辑:能否请您检查,如果这是你的顶线在你的清单文件:
Can you please check if this is your TOP line in your manifest file:
<?xml version="1.0" encoding="utf-8"?>
这篇关于permission.READ_CONTACTS似乎不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!