/storage/emulated/0/Download/copy_download.db (Permission denied) error handling method

Error message:

 

In fact, this problem is due to the update of the permission mechanism in Android 6.0. Before 6.0, the permission to write to the sd card only needs to be added in the manifest file. 

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

That's it, and in version 6.0 and above, access to some public directories such as: /storage/emulated/0/Download

You need to use code in the activity to request some sensitive permissions, including the operation permissions on the sd card. There are several solutions to this problem:

  1. Open the virtual machine's Setting–>Apps–>find your application–>click Permissions–>manually open the required permissions
  2. Set targetSdkVersion to less than 23, then recompile
  3. Manually add the code to request permission in the activity. For the specific code, please refer to the following short book link: 
    Android 6.0 Runtime Permission Processing 

Another: After Android 10+, you need to add android:requestLegacyExternalStorage="true" in the AndroidManifest.xml application tag

    <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:requestLegacyExternalStorage="true"
            tools:targetApi="q"
            android:supportsRtl="true"
            android:theme="@style/AppTheme" >

Guess you like

Origin blog.csdn.net/wh445306/article/details/129742920