附加到Android MediaStore中的文件
目前正在尝试编辑一个文件,该文件存储在Android 11/Android R MediaStore API的下载集合中。我使用以下代码编辑该文件:附加到Android MediaStore中的文件,android,android-storage,android-11,Android,Android Storage,Android 11,目前正在尝试编辑一个文件,该文件存储在Android 11/Android R MediaStore API的下载集合中。我使用以下代码编辑该文件: while (cursor.moveToNext()) { long id = cursor.getLong(idColumn); Uri contentUri = ContentUris.withAppendedId(MediaStore.Downloads
while (cursor.moveToNext()) {
long id = cursor.getLong(idColumn);
Uri contentUri = ContentUris.withAppendedId(MediaStore.Downloads.EXTERNAL_CONTENT_URI, id);
try (OutputStream myFile = getContentResolver().openOutputStream(contentUri, "wa")) {
myFile.write("XXX Dies ist eine Aenderung XXX".getBytes(Charset.forName("UTF-8")));
}
catch (Exception e){}
}
像这样创建后,ala使用较短的初始内容:
try {
OutputStream fos = resolver.openOutputStream(Objects.requireNonNull(anUri));
fos.write("File Hallo".getBytes(Charset.forName("UTF-8")));
fos.close();
}
当第二个代码运行时,我没有得到完整的消息。相反,Android似乎开始覆盖该文件,但只写入文件原始长度所能占用的信息
从我阅读的文档来看,我所能做的就是a)制作一份本地副本,b)将其推回到MediaStore。这是真的吗?是否无法编辑文件系统中已经存在的文件?您如何测试此功能?注意,您确定文件不包含完整更新的过程是什么?我使用Android Studio的文件浏览器窗格检查了内容,并在本地编辑器中打开了文件!如果您可以创建一个可复制的示例应用程序。如果你这样做了,并且你想到了,在这里弹出一个链接到这个问题!正如您所命令的,Commonware-您如何测试它?注意,您确定文件不包含完整更新的过程是什么?我使用Android Studio的文件浏览器窗格检查了内容,并在本地编辑器中打开了文件!如果您可以创建一个可复制的示例应用程序。如果你这样做了,并且你想到了,在这里弹出一个链接到这个问题!公用软件,正如你所吩咐的-