读/写联系时权限被拒绝没有语法错误

时间:2015-10-15 00:14:55

标签: android

全部,即使我的清单看起来格式正确,我似乎也收到了安全权限错误,并且在声明权限时语法是正确的。我已经检查了stackoverflow上的其他几个帖子,但是我一直无法解决它。我假设它可能是运行应用程序的模拟器的问题。我目前正在使用23.的目标SDK。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.thundercats.ho.contactfinder" >

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

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />

    <application
        android:name=".GetHashKeyApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/FBAPPID" />
        <activity
            android:name=".FindContactActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" >
        </activity>
        <activity
            android:name=".ContactDetailsActivity"
            android:label="@string/title_activity_contact_information"
            android:theme="@android:style/Theme.NoTitleBar" >
        </activity>
        <activity android:name=".MainActivity"
            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>
        <activity android:name="com.facebook.FacebookActivity"
            android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:label="@string/app_name" >
            </activity>
    </application>

</manifest>

异常

10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{a99c081 5182:com.thundercats.ho.contactfinder/u0a53} (pid=5182, uid=10053) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:1599)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:1552)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3550)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.app.ActivityThread.acquireProvider(ActivityThread.java:4778)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1468)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.content.ContentResolver.query(ContentResolver.java:475)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.content.ContentResolver.query(ContentResolver.java:434)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at utils.ContactHelper.retrieveContacts(ContactHelper.java:34)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at com.thundercats.ho.contactfinder.ContactListFragment.initializeData(ContactListFragment.java:44)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at com.thundercats.ho.contactfinder.ContactListFragment.onCreateView(ContactListFragment.java:31)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1016)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1197)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1562)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:535)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.View.measure(View.java:18788)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.View.measure(View.java:18788)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.View.measure(View.java:18788)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.View.measure(View.java:18788)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.View.measure(View.java:18788)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.Choreographer.doCallbacks(Choreographer.java:670)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:606)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
    10-14 18:09:48.531 5182-5182/com.thundercats.ho.contactfinder E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)

1 个答案:

答案 0 :(得分:2)

在Android 6.0(API 23)和目标API 23上,您使用runtime permissionsthis blog post中解释的documentation on runtime permissions

在能够使用READ_CONTACTS等危险权限之前,您需要在运行时请求权限。