在apk中包含自定义文件 [英] include custom file in apk

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

问题描述

我正在创建一个应用程序并使用Ratio.xml作为数据库。我在文件夹的外部存储中手动添加了这个文件,我的应用程序正在运行。



我想在我的apk包中包含这个文件并在任何一个中安装此文件设备中的文件夹而不是外部存储。我在资产文件夹中添加了这个文件,但它是只读的,我无法修改并保存在这个文件中。请告诉我把这个文件放在我的项目中并创建包。

I am creating an app and use Ratio.xml as database. I added this file manually in external storage in a folder and my app is working.

I want to include this file in my apk package and install this file in any of the folder in the device and not in external storage . I added this file in asset folder but it is read only, I can't modify and save in this file. Please tell me where to put this file in my project and create package.

推荐答案

我会保留<原始版本的< b>资产文件夹中的Ratio.xml ,在启动应用程序时,我会通过阅读 Ratio.xml 的内容并将其写入a来将其复制到内部存储使用 Context.openFileOutput 的新文件。显然只会覆盖副本(如果它还没有)。



调用 Context.openFileOutput 将返回 FileOutputStream 所以使用它来读取和写入文件几乎是标准的Java。该文件对您的应用程序是私有的。我认为使用内部存储 [ ^ ]是最好的解决方案,但还有其他方法 [ ^ ]为您实现相同但不同的方式。



希望这会有所帮助,

Fredrik
I would keep the "original" version of your Ratio.xml in the asset folder, and on start-up of the app I would copy it to the Internal Storage by reading the contents of Ratio.xml and writing it to a new file using Context.openFileOutput. Obviously only overwrite the copy if it's not already there.

Calling Context.openFileOutput will return a FileOutputStream so using that it's pretty much standard Java to read and write the file. The file will be private to you application. I think using the Internal Storage[^] is the best solution here, but there are other ways[^] for you to achieve the same, but in different ways.

Hope this helps,
Fredrik


参见 https://www.youtube.com/watch?v=A-cIZoSa5bA [ ^ ],它适用于SQLite数据库,但原理是相同的。
See https://www.youtube.com/watch?v=A-cIZoSa5bA[^], it's for an SQLite database, but the principle is the same.


这篇关于在apk中包含自定义文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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