无法在 Android P 中写入文件 [英] Unable to write files in Android P

查看:47
本文介绍了无法在 Android P 中写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 Android P 存储卡中写入文件.相同的代码在 Android O 中运行良好.

I couldn’t write files in Android P Memory Card. The same code is working fine in Android O.

new File(file.getParent()).mkdirs();
output = new ObjectOutputStream(new FileOutputStream(file));
output.writeObject(obj);

我可以从同一设备(内存卡)读取文件,但是当我尝试写入文件时,它抛出权限被拒绝异常.

I am able to read the files from the same device(Memory Card), but when I try to write the file, it is throwing Permission Denied exception.

最初它抛出我没有这样的文件或目录,但在授予 root 权限后,它抛出 Permission Deniod 异常.

Initially it was throwing me No such file or Directory, but after giving root permissions, it is throwing Permission Deniod exception.

注意:我的应用程序是系统特权应用程序,并且我已经通过 adb root 授予 Devicewith root 权限,检查了 Android Manifest 文件中的权限,它们看起来不错.

Note: My app is system privileged app and also I have given the Devicewith root permission by adb root, checked the permissions in Android Manifest file, they look fine.

推荐答案

使用 DocumentContract 和 DocumentFile 使用 URI 创建文件和文件夹.

Used DocumentContract and DocumentFile to create files and folders using URI.

这篇关于无法在 Android P 中写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆