Android 10 error: open failed: EACCES (Permission denied)

 

1. Environment

Project version setting:

  1. compileSdkVersion 29
  2. buildToolsVersion "29.0.2"
  3. defaultConfig {
  4. applicationId "com.example.myapplication"
  5. minSdkVersion 26
  6. targetSdkVersion 29
  7. versionCode 1
  8. versionName "1.0"
  9. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  10. }

Xiaomi mix2s for testing,The Android version is 10.0

Second, the solution

At the beginning, read and write permissions have been declared in AndroidManifest.xml,

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

But when accessing the album, I still get an error:

open failed: EACCES (Permission denied)

Online slaveChange permissions in phone settings,orCheck storage permissions on the goWhatever doesn't work for me.

And found an effective method, inAndroidManifest.xmlAdd a sentence:

android:requestLegacyExternalStorage="true"

The location is as follows

  1. <application
  2. android:allowBackup="true"
  3. android:icon="@mipmap/ic_launcher"
  4. android:label="@string/app_name"
  5. android:roundIcon="@mipmap/ic_launcher_round"
  6. android:supportsRtl="true"
  7. android:theme="@style/AppTheme"
  8. android:requestLegacyExternalStorage="true">

Then successfully solve the problem!

3. Reason

Android Q partition storage permission changes and adaptation issues:

In order to give users more control over their files and limit the situation of file confusion,Android Q modifies APP's method of accessing files in external storage. The new feature of external storage is called Scoped Storage.

Android Q still uses READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE as user-oriented storage-related runtime permissions, but now Even with these permissions, access to external storage is restricted. The scenario where the APP needs these runtime permissions has changed, and the visibility of the external storage to the APP has also changed in various situations.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

How to extract filename from Uri?

Now, we can extract filename with and without extension :) You will convert your bitmap to uri and get the real path of your file. Now w...