简体   繁体   English

在Android Marshmallow上包含预先填充的sqlite数据库与应用程序时的权限问题

[英]Permission trouble when including pre-populated sqlite database with app on Android Marshmallow

I'm trying to include a prepopulated sqlite database with my app. 我正在尝试在我的应用程序中包含一个预先填充的sqlite数据库。 I have put it at main/assets/dbname.db and copying it in onCreate() of my custom Application subclass. 我把它放在main/assets/dbname.db并将其复制到我的自定义Application子类的onCreate()中。

It works great for lower versions of Android. 它适用于较低版本的Android。 But on Marshmallow, I'm hitting a barrier with permissions. 但是在棉花糖上,我正在通过许可进入障碍。 I cannot ask for storage writing permission unless I'm inside an activity. 除非我在活动中,否则我不能要求存储写入权限。 So I moved the db copying part inside the first activity that launches, inside onCreate() of the activity. 所以我将db复制部分移动到第一个启动的活动中,在活动的onCreate()中。 But then for some reason, right after I grant the permission, my app closes. 但由于某种原因,在我授予许可后,我的应用程序关闭了。 I have to start it again for it to work. 我必须再次启动它才能工作。

I've been looking for best practices on how to provide a prepopulated database for Android Marshmallow and I haven't had much success. 我一直在寻找有关如何为Android Marshmallow提供预填充数据库的最佳实践,但我没有取得多大成功。 Any idea? 任何想法?

我最终使用这个插件Android SQLite资产助手似乎没有任何问题。

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

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