android - 权限被拒绝:android.Manifest.permission.READ_EXTERNAL_STORAGE

标签 android gradle permissions build.gradle android-external-storage

我已经阅读了所有类似的问题,但是找不到解决方案。这是android 10。
我需要你的帮助file.isFile()返回true。
但是file.canRead()返回false。因此,FileInputStream(file)导致以下错误;
android.system.ErrnoException:打开失败:EACCES(权限被拒绝)
list 文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
       <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.CAMERA" />
    
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
   <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="MyApp"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"

    android:name="androidx.multidex.MultiDexApplication">

    <activity android:name=".allresults"/>

    <activity android:name=".DiagnoseActivity">
        <intent-filter>
            <action android:name="com.dailystudio.deeplab.MainActivity" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".profileActivity" />

    <activity android:name=".LoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".MainActivity" />

    <activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
        android:theme="@style/Base.Theme.AppCompat"/> 

    
    </manifest>
gradle文件中的SDK版本为;
android {
    compileSdkVersion 29 // <====
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.HT1"
        minSdkVersion 23  // minSdkVersion 16  // <====
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        multiDexEnabled true

    }
Gradle代码在项目级别;
buildscript {
    ext.kotlin_version = '1.3.72' //'1.3.61'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

最佳答案

请尝试在android:requestLegacyExternalStorage="true"文件中的application标签中添加AndroidManifest.xml属性:

<application
    ...
    android:requestLegacyExternalStorage="true">
另外,您还应该在运行时请求该权限,请检查this link

关于android - 权限被拒绝:android.Manifest.permission.READ_EXTERNAL_STORAGE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62853375/

相关文章:

android - 如何更改 Android Studio 中的构建工具版本

Android Gradle 失败 多个 dex 文件定义 okhttp

已授予 Android 权限但仍被拒绝

android - 三星 S4 健康应用程序 API

java - SQLite异常: No such table even if there is table

android - 如何在同一 LinearLayout 中使高程投影到顶 View 上

grails - 适用于 Grails 3.x 的 Gradle DSL

c# - 在 Visual Studio 中发布后更改对 ASP.NET 文件夹的权限

permissions - 挂载共享 cifs 的始终权限为 777

android - 有没有办法检测应用程序是否与 Market 一起安装?