READ_EXTERNAL_STORAGE 显示许可但未显示 READ_EXTERNAL_STORAGE

READ_EXTERNAL_STORAGE shows permission but not READ_EXTERNAL_STORAGE

我正在尝试获取对外部存储的读写权限:

<uses-feature android:name="android.hardware.camera.any" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE "/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

请求权限代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  //works. dialog pops up
  ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 101);
  //doesnt work. dialog does not pop
  ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},  565);
}

但我有一个问题:问题是我只能“允许”允许读取存储的权限,而不是写入存储的权限。询问作者权限时会弹出对话框。我错过了什么吗?我知道如果 sdk 版本高于 marshmellow,你必须请求许可。权限询问也会在运行时发生(onClick 侦听器)。

在清单中必须在添加行后添加这些行才能显示所有数据

requestLegacyExternalStorage=true

我通过像这样添加 tools:remove="android:maxSdkVersion" 来修复:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>