gpt4 book ai didi

android - 将 Firebase 数据导出到文件

转载 作者:太空宇宙 更新时间:2023-11-03 13:46:01 29 4
gpt4 key购买 nike

我正在开发一款在 Android 上使用 Firebase 构建的应用。该应用程序用于跟踪目前接受我们护理的住院患者。我们的团队可以为每位患者输入进度记录,并添加您需要为每位患者执行的任务,并在完成后进行标记。我已经完成了所有这些,但是,我需要再添加一个选项,我可以在其中选择一名患者,并将当前 View (以及与主记录关联的所有多对一数据)导出到外部文件(可编辑文件),所以我们可以用它来写他/她的最终报告和总结。我在网上搜索过,发现很多建议将 View 导出为位图,然后导出为 pdf ...但这会使文档不可编辑。如果有人有任何想法,或者可以指出正确的方向,我不胜感激。最终格式不是真正的问题... pdf、txt、doc、html ....我想这并不重要,只要数据可以按当前 View 中的原样导出(订购和制作感),并且可以编辑。

任何帮助将不胜感激。谢谢。

最佳答案

我曾经做过一个应用程序,可以选择将数据导出到设备存储上的 txt 文件。这是我使用的方法:

public void exportTxt(String text){
if(Environment.getExternalStorageState().equalsIgnoreCase("mounted"))//Check if Device Storage is present
{
try {
File root = new File(Environment.getExternalStorageDirectory(), "MyAppFolder");//You might want to change this to the name of your app. (This is a folder that will be created to store all of your txt files)
if (!root.exists()) {
root.mkdirs();
}
File myTxt = new File(root, "filename.txt"); //You might want to change the filename
FileWriter writer = new FileWriter(myTxt);
writer.append(text);//Writing the text
writer.flush();
writer.close();
Toast.makeText(this, "File exported", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Error: "+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
else
Toast.makeText(this, "Can't access device storage!", Toast.LENGTH_SHORT).show();
}

不要忘记将此权限添加到您的 AndroidManifest.xml 文件中:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

因此,为了使用此方法,您需要做的就是将所有 currentView 数据分组到一个字符串中,并将其作为参数传递。

关于android - 将 Firebase 数据导出到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42063982/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com