Millie
Millie

Reputation: 71

Still permission denied after add "WRITE_EXTERNAL_STORAGE" in AndroidManifest.xml


solution: test target project must also add WRITE_EXTERNAL_STORAGE in AndroidManifest.xml

this question came from an android test project,which can't write test result into SDcard. Add WRITE_EXTERNAL_STORAGE into test target project can solve this problem.


Always throw permission denied when I use code below to write xml file into emulator's sdcard. I have added WRITE_EXTERNAL_STORAGE" in AndroidManifest.xml.

        @Override
public void onStart(){

    try {
        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        myWriter = new FileWriter(new File(root, TEST_RESULT+".xml"));          
        startResultOutput(myWriter);
    } catch (IOException e) {
        Log.d("TestInfo", "after new FileWriter: "+e.getMessage());
    }
    super.onStart();

}

catched IOExcetion, the message was: after new FileWriter: /mnt/sdcard/InterFace_test_result.xml (Permission denied)

Below is the manifest code

<application android:icon="@drawable/icon" android:label="@string/app_name">

<uses-library android:name="android.test.runner" />
</application>

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

SD card was mounted, because I can use another application to write file into external sd card.

Can anybody give me some suggestion?

PS: the emulator system is 2.3.3

Upvotes: 7

Views: 9878

Answers (2)

Adil Soomro
Adil Soomro

Reputation: 37729

Problem:

What I can understand is, You are adding permission two times

  1. one time in Application tag as an attribute
  2. and second time using <use-permission>

Solution:

Try removing any one of them.

Upvotes: 1

Wei Yang
Wei Yang

Reputation: 905

You should add permission tag <uses-permission> before <application> tag.

Upvotes: 0

Related Questions