相关疑难解决方法(0)

requestLegacyExternalStorage 在 Android 11 - API 30 中不起作用

Google 最近引入了一些与 API 29 中的存储 API 相关的更改,例如范围存储,我们通过在清单中添加“requestLegacyExternalStorage=true”来选择退出。但是现在当我定位SdkVersion 30 时,这似乎不再起作用。在此更改后,下载目录中的某些文件未列出 (File.listFiles)。

java storage android android-11

30
推荐指数
2
解决办法
4万
查看次数

在android 11(sdk 30)中,如何从下载文件夹上传pdf文件?我收到 EACCES 消息,但权限被拒绝

它在 android 10 中运行良好,带有 requestLegacyExternalStorage="true" 标签。该应用程序就像whatsapp,以便用户可以选择文件/图像/位置并将其发送给另一个用户。图像和位置工作正常,但我在上传文档时遇到错误。我认为我的应用不符合 MANAGE_EXTERNAL_STORAGE 权限。所以如果您有任何解决方案,请分享。

获得 READ_EXTERNAL_STORAGE 和 WRITE_EXTERNAL_STORAGE 运行时权限后我的文件选择器。

    Intent intent = new Intent();
    intent.setType("*/*");
    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(Intent.createChooser(intent, "Select File"), 1);
Run Code Online (Sandbox Code Playgroud)

在 OnActivityResult 中,我在“文件”中获取全局变量的文档。

       Uri uri = data.getData();
       // Log.e("cs","uri =>"+uri);

        file = new File(uri.getPath());

        final String[] split = file.getPath().split(":");//split the path.
        String filePath = split[1];//assign it to a string(your choice).

        //Log.e("cs","filepath=>"+filePath);

        file = new File(filePath);

       // Log.e("cs","file=>"+file.exists());
Run Code Online (Sandbox Code Playgroud)

当我上传文件时出现问题

    RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
    MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
Run Code Online (Sandbox Code Playgroud)

所以在改造中它会转到 onFailure 并且我收到错误 :: open failed: …

sdk android file-permissions

6
推荐指数
1
解决办法
3390
查看次数

标签 统计

android ×2

android-11 ×1

file-permissions ×1

java ×1

sdk ×1

storage ×1