Exception 'open failed: EACCES (Permission denied)' on Android

前端 未结 30 1421
[愿得一人]
[愿得一人] 2020-11-22 00:59

I am getting

open failed: EACCES (Permission denied)

on the line OutputStream myOutput = new FileOutputStream

相关标签:
30条回答
  • 2020-11-22 01:48

    Be aware that the solution:

    <application ...
        android:requestLegacyExternalStorage="true" ... >
    

    Is temporary, sooner or later your app should be migrated to use Scoped Storage.

    In Android 10, you can use the suggested solution to bypass the system restrictions, but in Android 11 (R) it is mandatory to use scoped storage, and your app might break if you kept using the old logic!

    This video might be a good help.

    0 讨论(0)
  • 2020-11-22 01:49

    My issue was with "TargetApi(23)" which is needed if your minSdkVersion is bellow 23.

    So, I have request permission with the following snippet

    protected boolean shouldAskPermissions() {
        return (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1);
    }
    
    @TargetApi(23)
    protected void askPermissions() {
        String[] permissions = {
                "android.permission.READ_EXTERNAL_STORAGE",
                "android.permission.WRITE_EXTERNAL_STORAGE"
        };
        int requestCode = 200;
        requestPermissions(permissions, requestCode);
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    // ...
        if (shouldAskPermissions()) {
            askPermissions();
        }
    }
    
    0 讨论(0)
  • 2020-11-22 01:49

    When your application belongs to the system application, it can't access the SD card.

    0 讨论(0)
  • 2020-11-22 01:51

    Add android:requestLegacyExternalStorage="true" to the Android Manifest It's worked with Android 10 (Q) at SDK 29+
    or After migrating Android X.

     <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon=""
        android:label=""
        android:largeHeap="true"
        android:supportsRtl=""
        android:theme=""
        android:requestLegacyExternalStorage="true">
    
    0 讨论(0)
  • 2020-11-22 01:51

    after adding permission solved my problem

    <uses-permission android:name="android.permission.INTERNET"/>
    
    0 讨论(0)
  • 2020-11-22 01:52

    Add Permission in manifest.

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
    0 讨论(0)
提交回复
热议问题