简体   繁体   English

Android:使用预加载的数据库文件安全吗?

[英]Android: is it safe to use a preloaded database file?

I have a huge set of data that I want to insert into the sqlite database before the user is able to do anything inside my application. 我要在用户能够在我的应用程序内执行任何操作之前将大量数据插入到sqlite数据库中。 Right now I have all my data stored in CSV files, then I parse those files and use DatabaseUtils.InsertHelper to do a bulk insertion, but this is taking to long to complete. 现在,我将所有数据存储在CSV文件中,然后解析这些文件并使用DatabaseUtils.InsertHelper进行批量插入,但这需要很长时间才能完成。

I stumbled on this tutorial some time ago and I'm wondering: is it safe to distribute a pre-generated sqlite file? 我前段时间偶然发现了教程,我想知道:分发预先生成的sqlite文件是否安全? Can I run into problems due to different versions of SQLite on different devices? 由于在不同设备上使用不同版本的SQLite,我是否会遇到问题?

I'm planning to support Android 2.1 and higher. 我打算支持Android 2.1及更高版本。

I suppose it depends on your definition of safe. 我想这取决于您对保险柜的定义。 It is certainly possible as long as the database conforms to the metadata table spec Android expects, which is what that tutorial you stumbled upon is showing you. 只要数据库符合Android期望的元数据表规范,这肯定是可能的,这是您偶然发现的教程所展示的内容。 You won't have to worry about version conflicts with SQLite as that is a package built into the core platform and isn't something OEMs add to or implement anything on top of. 您不必担心与SQLite的版本冲突,因为它是内置在核心平台中的软件包,并且不是OEM可以添加或实现的任何东西。

However, if by safe you mean "protected" you would need to take special steps to ensure that your database is not externally readable if that is a concern. 但是,如果您的意思是“受保护的”,那么您需要采取特殊的措施来确保数据库在外部不可读(如果这样做的话)。 If you simply place the preconstructed DB into assets/ and copy it over, anyone who can properly deconstruct an APK file can view your database data. 如果您只是将预先构建的数据库放入assets/并将其复制过来,则可以正确解构APK文件的任何人都可以查看您的数据库数据。 This may or may not be an issue for you. 这可能对您来说不是问题。

最好的方法是将这些数据填充到数据库中,将数据库保留在资产中,然后将其复制到设备上。 您可以在此处遵循此完整的示例代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM