Android的保存在内部/外部存储应用程序设置/数据 [英] Android save app settings/data in Internal/External Storage

查看:144
本文介绍了Android的保存在内部/外部存储应用程序设置/数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助与理解,我能做些什么,不能在机器人。我工作的应用程序,它需要询问用户在第一次启动选择设备(内部/外部存储),其中保存其中我的应用程序下载互联网上的数据。所以,我试图找到答案有关此问题的几个问题:

  1. 是否有任何限制内部/外部存储在Android中的单个应用程序的数据。
  2. 我可以设置源码数据库而我的应用程序使用,如果我能,它是一个很好的做法还是不目录。
  3. 我应该怎么考虑,如果用户决定从内部改变应用程序的数据的目标到外部存储。我应该创建的所有文件夹,再等,或Android平台会自动做?

在此先感谢!

解决方案
  1. 您在外部存储(SD卡)的限制是由它的容量只有决定的,我不知道有关内部存储,也许是同样的情况。
  2. 您可以扩展SQLiteOpenHelper并创建自己的数据库适配器,它会管理你的数据库,并将其存储在SD卡或/数据/数据​​库目录。我认为这是最好不要放置在SD卡数据库,因为任何其他的应用程序可以访问它。另一方面,/数据/文件夹是私人的。
  3. 这是一件棘手的事情。你应该小心,而复制数据。检查是否文件的目录中,写入之前。这是更好地尝试给他们写信之前,明确创建的所有文件和目录。

<一个href="http://stackoverflow.com/questions/8052262/cant-copy-sqlite-database-from-assets/8052459#8052459">Here 是数据库助手的访问数据库的一个很好的例子。您可以修改,以便它可以同时使用外部和内部存储。

I need a little help with understanding what can I do and cannot in android. I'm working on application which needs to ask user in first start to select a device (internal/external storage) where to save the data which my application is downloading over internet. So I'm trying to find answer for a few questions about this issue :

  1. Is there any limit for data in internal/external storage in Android for a single application.
  2. Can I set the directory of sqlite database which my app is using and If I can, is it a good practice or not.
  3. What should I consider when user decide to change the destination of application's data from internal to external storage. Should I create all the folders and etc. again or Android platform is doing it automatically?

Thanks in advance!

解决方案

  1. Your limit on external storage(SDCARD) is determined only by its capacity, I'm not sure about the internal storage, maybe it's the same situation.
  2. You can extend SQLiteOpenHelper and create your own DB adapter, which will manage your database and store it on SD card or /data/databases directory. I think that it's better not to place database on SDCARD, because any other app can access it there. On the other hand, /data/ folder is private.
  3. It's tricky thing. You should be careful while copying data. Check whether directory of file exist, before writing into them. It's better to explicitly create all files and directories before trying to write to them.

Here is a good example of Database Helper for accessing database. You can modify it so it can use both external and internal storage.

这篇关于Android的保存在内部/外部存储应用程序设置/数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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