ngCordova SQLite does not work on Android 6.0 or higher

3

Good community, testing my application, the SQLite plugin does not work and the plugin to detect the type of Network to which the ngCordova device for Android is connected, when I try to enter these messages appear.

deviceready has not fired after 5 seconds. cordova.js:1216 
Channel not fired: onCordovaInfoReady cordova.js:1216 
Channel not fired: onCordovaConnectionReady cordova.js:1216 
Channel not fired: onFileSystemPathsReady

And when I enter one of the views, and you must show me information about it, this appears.

database already open: unicesar.db SQLitePlugin.js:106 
new transaction is waiting for open operation SQLitePlugin.js:80 DB 
opened: unicesar.db

I have a device with android 4.2.2 and it works perfectly, but on several devices with Android 6.0 or higher it does not show me anything.

My database configuration is as follows:

 db = $cordovaSQLite.openDB({
            name: "unicesar.db",
            location: "default"
        });
    
asked by Pedro Miguel Pimienta Morales 30.05.2017 в 17:56
source

1 answer

1

I had a similar problem with Android and iOS, try to do it like this:

Within your app.js , specifically within the method run

document.addEventListener('deviceready', function() {
    //Aqui declaras tus tablas
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS ....");
});

And in your controllers:

document.addEventListener('deviceready', function() {
    var db = null;
    if (ionic.Platform.isIOS() || ionic.Platform.isIPad()) {
        db = window.sqlitePlugin.openDatabase({ name: 'unicesar.db', location: 'default' });
    } else {
        db = window.openDatabase("unicesar.db", '1.0', 'Tu DB', 1024 * 1024 * 100);
    }
});

EDITING

Replaces:

db = $cordovaSQLite.openDB({
    name: "unicesar.db",
    location: "default"
});

By:

var db = null;
if (ionic.Platform.isIOS() || ionic.Platform.isIPad()) {
    db = window.sqlitePlugin.openDatabase({ name: 'unicesar.db', location: 'default' });
} else {
    db = window.openDatabase("unicesar.db", '1.0', 'Tu DB', 1024 * 1024 * 100);
}

I advise you, that within your app.js you initialize the database and from the controllers you only access and execute the pertinent queries.

app.js

 document.addEventListener('deviceready', function() {
     var db = null;

     if (ionic.Platform.isIOS() || ionic.Platform.isIPad()) {
         var db = window.sqlitePlugin.openDatabase({ name: 'unicesar.db', location: 'default' });
     } else {
         var db = window.openDatabase("unicesar.db", '1.0', 'Fepachi DB', 1024 * 1024 * 100);
     }
     crearTablaPerfil = "CREATE TABLE IF NOT EXISTS Estudiante(Cedula integer primary key, Nombre text, Apellido text," +
         " Rol integer, Facultad text, Programa text, Semestre integer)";
     crearTablaHorario = "CREATE TABLE IF NOT EXISTS Horario(Codigo text primary key, Grupo integer," +
         "Nombre text, Creditos integer, Dia text, Hora text, Lugar text, Profesor text)";
     crearTablaCalificaciones = "CREATE TABLE IF NOT EXISTS Calificaciones(Codigo text primary key, Grupo integer," +
         "NombreAsig text, Nota1 float, Nota2 float, Nota3 float, Habilitacion float)";
     crearTablaTareasEstu = "CREATE TABLE IF NOT EXISTS TareasEstu(Fila integer primary key, Texto text, Fecha text)";
     $cordovaSQLite.execute(db, crearTablaPerfil);
     $cordovaSQLite.execute(db, crearTablaHorario);
     $cordovaSQLite.execute(db, crearTablaCalificaciones);
     $cordovaSQLite.execute(db, crearTablaTareasEstu);
 });
    
answered by 30.05.2017 / 17:59
source