From 4e0e569479f5e2a2fd1af4258df6a0b827a3478b Mon Sep 17 00:00:00 2001 From: nero120 Date: Sat, 26 Mar 2022 07:34:43 +0000 Subject: [PATCH] Switched to using the cordova-sqlite-storage plugin for android for better device support (resolves #384). --- res/android/package.json | 6 ++--- .../android-store/android-store.service.ts | 24 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/res/android/package.json b/res/android/package.json index 631f6547..83e8b7ea 100644 --- a/res/android/package.json +++ b/res/android/package.json @@ -30,7 +30,7 @@ "cordova-plugin-snackbar": "github:xbrowsersync/cordova-plugin-snackbar#2.2.2", "cordova-plugin-whitelist": "1.3.4", "cordova-plugin-x-socialsharing": "github:xbrowsersync/SocialSharing-PhoneGap-Plugin#5.6.6", - "cordova-sqlite-evcore-extbuild-free": "^0.12.1", + "cordova-sqlite-storage": "^6.0.0", "es6-promise-plugin": "^4.2.2" }, "cordova": { @@ -54,10 +54,10 @@ "cordova-plugin-exit": {}, "cordova-plugin-globalization": {}, "cordova-plugin-app-version": {}, - "cordova-sqlite-evcore-extbuild-free": {}, "com-darryncampbell-cordova-plugin-intent": {}, "cordova-plugin-android-dark-mode-support": {}, - "cordova-plugin-androidx-adapter": {} + "cordova-plugin-androidx-adapter": {}, + "cordova-sqlite-storage": {} }, "platforms": [ "android" diff --git a/src/modules/android/android-shared/android-store/android-store.service.ts b/src/modules/android/android-shared/android-store/android-store.service.ts index 77ee46a0..fe8a7d9c 100644 --- a/src/modules/android/android-shared/android-store/android-store.service.ts +++ b/src/modules/android/android-shared/android-store/android-store.service.ts @@ -214,19 +214,17 @@ export class AndroidStoreService extends StoreService { return this.$q.resolve(this.db); } return this.$q((resolve, reject) => { - window.resolveLocalFileSystemURL(window.cordova.file.externalDataDirectory, (dataDir: any) => { - window.sqlitePlugin.openDatabase( - { name: this.dbName, androidDatabaseLocation: dataDir.toURL() }, - resolve, - reject - ); - }); - }) - .then((db) => { - this.db = db; - return db; - }) - .catch((err) => this.handleSqlError(err)); + try { + this.db = window.sqlitePlugin.openDatabase({ + androidDatabaseProvider: 'system', + location: 'default', + name: this.dbName + }); + resolve(this.db); + } catch (err) { + reject(new FailedLocalStorageError(err.message)); + } + }); } protected removeFromStore(keys: string[] = []): ng.IPromise {