Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 269
Millie Avatar asked Dec 24 '11 15:12

Millie


People also ask

How do I grant permission to write external storage?

To read and write data to external storage, the app required WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE system permission. These permissions are added to the AndroidManifest. xml file. Add these permissions just after the package name.

What does Android permission Write_external_storage do?

WRITE_EXTERNAL_STORAGE does not give any privileges in Android 11 (API 30), it does nothing at all, therefore in API 11 you need to set the maxSdkVersion to 29. If in Android 10 (API 29) you are also not using requestLegacyExternalStorage then set maxSdkVersion to 28 instead of 29.

How do you declare permission in manifest?

Add declaration to app manifest To declare a permission that your app might request, include the appropriate <uses-permission> element in your app's manifest file. For example, an app that needs to access the camera has this line in AndroidManifest. xml : <manifest ...>


1 Answers

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.

like image 154
Adil Soomro Avatar answered Oct 16 '22 01:10

Adil Soomro