简体   繁体   English

不访问 API-29 中的外部存储

[英]Doesn't Access to external storage in API-29

The following code works well in the lower API-29.以下代码在较低的 API-29 中运行良好。 But when using API-29, it gives this access denied to external storage.但是当使用 API-29 时,它会拒绝对外部存储的访问。

public void persistFile(byte[] bytes, String path, String fileName) throws IOException {
    OutputStream fOut = null;
    File picDirectory = new File(path);
    File file = new File(path, fileName); 
    fOut = new FileOutputStream(file);
    fOut.write(bytes); 
    fOut.flush();  
    fOut.close();  
}

AndroidManifest.xml AndroidManifest.xml

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

On Android 10 file paths outside of your App's private directories are worthless by default, you can temporarily enable requestLegacyExternalStorage until Android 11 (which is now out in preview)在 Android 10 上,默认情况下,应用私有目录之外的文件路径毫无价值,您可以暂时启用 requestLegacyExternalStorage,直到 Android 11(现在处于预览版中)

See https://developer.android.com/training/data-storage请参阅https://developer.android.com/training/data-storage

Going forward it is probably best just to use Media Store or Storage Access Framework展望未来,最好只使用媒体存储或存储访问框架

https://developer.android.com/training/data-storage/shared https://developer.android.com/training/data-storage/shared

Can useing add android:requestLegacyExternalStorage="true" in manifest application tag.可以使用在清单应用程序标签中添加android:requestLegacyExternalStorage="true"

<manifest ... >
  <!-- This attribute is "false" by default on apps targeting
       Android 10 or higher. -->
  <application android:requestLegacyExternalStorage="true" ... >
    ...
  </application>
</manifest>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM