permission.READ_CONTACTS似乎不工作 [英] permission.READ_CONTACTS does not seem to work

查看:1417
本文介绍了permission.READ_CONTACTS似乎不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个简单的应用程序,通过用户的联系人浏览。不幸的是我不断收到以下错误:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆