即使在向清单文件添加权限之后,READ_EXTERNAL_STORAGE的权限也会被拒绝

时间:2015-02-10 02:06:59

标签: android

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:exported ="true">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />

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

    <activity
        android:name=".ListActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".ViewPhotoActivity"
        android:label="@string/title_activity_view_photo"
        android:parentActivityName=".ListActivity">
    </activity>

    <activity
        android:name=".AddPhotoActivity"
        android:label="@string/title_activity_add_photo"
        android:parentActivityName=".ListActivity">
    </activity>
</application>

但是我仍然收到此错误:

Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/2519 from pid=5397, uid=10190 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

如果我在清单文件中遗漏了某些内容,有人可以指出吗?

2 个答案:

答案 0 :(得分:1)

将权限置于<application>之外(上方)。

答案 1 :(得分:0)

清单文件的结构

<manifest>
<uses-permission />
<permission />
<permission-tree />
<permission-group />
<instrumentation />
<uses-sdk />
<uses-configuration />  
<uses-feature />  
<supports-screens />  
<compatible-screens />  
<supports-gl-texture />  

<application>

    <activity>
        <intent-filter>
            <action />
            <category />
            <data />
        </intent-filter>
        <meta-data />
    </activity>

    <activity-alias>
        <intent-filter> . . . </intent-filter>
        <meta-data />
    </activity-alias>

    <service>
        <intent-filter> . . . </intent-filter>
        <meta-data/>
    </service>

    <receiver>
        <intent-filter> . . . </intent-filter>
        <meta-data />
    </receiver>

    <provider>
        <grant-uri-permission />
        <meta-data />
        <path-permission />
    </provider>

    <uses-library />

</application>
</manifest>

这需要是developers.android.com所示的清单结构 还请检查设备与设备的USB连接是否与媒体设备不一致,因为当它作为媒体设备连接时,您的SD卡已在使用中,请尝试将其更改为连接为相机,希望这可以解决你的问题。最好!快乐的编码!