Read file in android - file permission denied

后端 未结 3 746

I want to read file from external storage. I uploaded the file in Eclipse DDMS to storage/sdcard (image below). But whenever I tried to read, I got an error of permission de

相关标签:
3条回答
  • 2021-01-17 08:57

    Make sure you have added the permission to read external storage in your manifest file.

     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    
    0 讨论(0)
  • 2021-01-17 09:12

    I was experiencing the same problem and it can be easily removed by following either of these steps: 1. Install your app by using -g if installing on Android N and O versions. 2. Grant permission manually Settings->apps->"app_name"->Permissions->Enable Switch

    For Both steps 1 and 2, define uses-permission

    android:name="android.permission.WRITE_EXTERNAL_STORAGE" and uses-permission 
    android:name="android.permission.READ_EXTERNAL_STORAGE" in AndroidManifest.xml
    

    Like this :

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="...">
    
    
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <!-- all permissions here -->
        <application
            ...
    
    0 讨论(0)
  • 2021-01-17 09:14

    Storage permission needs to be given by the user before accessing the functionality

    Add Dependency:

    dependencies:
      permission_handler: ^5.0.1
    

    Code Snippet:

          var status = await Permission.storage.status;
           if (status.isUndetermined) {
                // You can request multiple permissions at once.
                Map<Permission, PermissionStatus> statuses = await [
                  Permission.storage,
                ].request();
                print(statuses[Permission.storage]); // it should print PermissionStatus.granted
              }
    
    0 讨论(0)
提交回复
热议问题