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

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

问题描述

我无法在Android P存储卡中写入文件。

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的root权限的Device,检查了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天全站免登陆