Permission Denial: … requires android.permission.W

2019-04-06 13:34发布

问题:

So the latest wall I've hit is in trying to write to the sdcard with my program. I'm getting:

[2011-05-28 10:00:16 - LatinDictionary] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.joelman.latindictionary/.LatinDictionary } from null (pid=-1, uid=-1) requires android.permission.WRITE_EXTERNAL_STORAGE

As you can see from my manifest below, I've added the permission (I also tried adding it to each of the activities, to no avail). What am I missing?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.joelman.latindictionary"
      android:versionCode="1"
      android:versionName="1.0">
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
     <application android:icon="@drawable/icon" android:label="@string/app_name" android:permission="android.permission.WRITE_EXTERNAL_STORAGE">
     <activity android:name=".LatinDictionary">
     <intent-filter>
     <action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
<intent-filter><action android:name="android.intent.action.SEARCH"></action>
</intent-filter>
</activity>

<provider android:name="DictionaryProvider" android:authorities="com.joelman.latindictionary.DictionaryProvider"></provider>
</application>

</manifest> 

TIA, Joel

回答1:

It should be like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.joelman.latindictionary"
      android:versionCode="1"
      android:versionName="1.0">
     <application android:icon="@drawable/icon" android:label="@string/app_name" android:permission="android.permission.WRITE_EXTERNAL_STORAGE">
     <activity android:name=".LatinDictionary">
     <intent-filter>
     <action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
<intent-filter><action android:name="android.intent.action.SEARCH"></action>
</intent-filter>
</activity>

<provider android:name="DictionaryProvider" android:authorities="com.joelman.latindictionary.DictionaryProvider"></provider>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
</manifest> 


回答2:

Put the permission line outside the application tag, but within the manifest one