Can't access pre populated SQLite database using PhoneGap/Cordova in Android

前端 未结 3 815
面向向阳花
面向向阳花 2020-12-20 09:58

We are trying to create a mobile app using PhoneGap/Cordova. We need to ship this app with a pre-populated SQLite db. We are able to copy the DB using below code. But when w

3条回答
  •  悲哀的现实
    2020-12-20 10:34

    In first place, can trying with the next DB file name:

    0000000000000001.db
    

    And for load file:

    File dbFile = getDatabasePath(".0000000000000001db");
    

    The DB file needs to be in the next route:

    yourProyect/assets/0000000000000001.db
    

    I recommend use "SQLitePlugin":

    SQLitePlugin GitHub

    In the "onDeviceReady()" function i use:

    if(!dbCreated){
        db = window.sqlitePlugin.openDatabase("0000000000000001", "1.0", "My Database", -1);
    }
    

提交回复
热议问题