[英]Exception while using SQLiteAssetHelper class
I am trying to use SQLiteAssetHelper to copy my pre-populated db into android app. 我正在尝试使用SQLiteAssetHelper将预先填充的数据库复制到android应用中。 I have Android-7 on my device(Nvidia Shield & Motorola Phone).
我的设备(Nvidia Shield和Motorola Phone)上装有Android-7。 From Settings->App->MyApp I have enabled Calender , Location & Storage permissions
从设置->应用程序-> MyApp我启用了日历 , 位置和存储权限
I have following permission in Manifest file as well 我在清单文件中也具有以下权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
When I keep my db in assets/databases/databases
folder, I get following exception: 当我将数据库保留在
assets/databases/databases
文件夹中时,出现以下异常:
Caused by: com.readystatesoftware.sqliteasset.SQLiteAssetHelper$SQLiteAssetException: Unable to write /data/user/0/com.funcheap.funmapsf/databases/databases/MySFfuncheapDatabase.db to data
引起原因:com.readystatesoftware.sqliteasset.SQLiteAssetHelper $ SQLiteAssetException:无法将/data/user/0/com.funcheap.funmapsf/databases/databases/MySFfuncheapDatabase.db写入数据
When I keep my db in assets/databases
folder, I get following exception: 当我将数据库保留在
assets/databases
文件夹中时,出现以下异常:
Caused by: com.readystatesoftware.sqliteasset.SQLiteAssetHelper$SQLiteAssetException: Missing databases/databases/MySFfuncheapDatabase.db file (or .zip, .gz archive) in assets, or target folder not writable
引起原因:com.readystatesoftware.sqliteasset.SQLiteAssetHelper $ SQLiteAssetException:资产或目标文件夹中的数据库/数据库/MySFfuncheapDatabase.db文件(或.zip,.gz归档文件)不可写
Unfortunately, this SO question doesnt help me 不幸的是,这个问题对我没有帮助
As @miket said if you reference the internal path Android will use that reference I had this issue and this was my very sloppy test code NOTE commented out call 正如@miket所说的,如果您引用内部路径,Android将使用该引用,我遇到了这个问题,这是我非常草率的测试代码。
public void getINTERNAL(){
Context context = this;
File file = new File(context.getFilesDir().getAbsolutePath());
String NT = String.valueOf(file);
THE_PATH = NT+"/";
System.out.println("INTERNAL PATH =========> "+THE_PATH);
}
public void getAvailable(){
//getINTERNAL();
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED) && (!state.equals(Environment.MEDIA_MOUNTED_READ_ONLY))) {
File removable = ContextCompat.getExternalFilesDirs(this, null)[1];
THE_PATH = String.valueOf(removable);
if(THE_PATH.length() > 4) {
//THE_PATH = THE_PATH.substring(0, THE_PATH.length() - 5);
THE_PATH = THE_PATH + "/Documents/";
System.out.println("new path ====> "+THE_PATH);
}
System.out.println("EXTERNAL PATH ====> " + THE_PATH);
System.out.println("Internal Path used if EXTERNAL PATH = NULL ");
//getINTERNAL(); DO NOT CALL HERE YOU WILL CHANGE THE_PATH TO internal
// no need to set THE_PATH for internal storage it will default on its own
// WHY DOES THIS HAPPEN THE_PATH variable is PUBLIC STATIC hence it is GLOBAL
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.