Android:从API 29中的现有URI覆盖文件

问题描述

以下代码采用String并将内容保存到现有文件Uri中。这些代码在Android pre API 29之前运行良好。

public void saveFile(String text,Uri existingSourceUri)
{
    try {

    ContentResolver cr = getContentResolver();
    OutputStream os = cr.openOutputStream(existingSourceUri);

    os.write(text.getBytes());
    os.flush();
    os.close();


    } catch (Exception e) {
       //show error message
    }
}

使用Android API 29+,该行为不固定。例如,如果第一次使用某个text调用该函数,则文件将被正确保存。但是,如果第二次text为空,则不会保存该文件。

有帮助吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)