mardi 2 février 2016

Creating database in a custom user defined path in phonegap for android

So here is the case:

I am working on creation of a plugin for phonegap (android) and the plugin that is created uses a pre populated database of phonegap. The default path of database creation in phonegap by far I know is like this:

"/data/com.example.hello/app_database/file__0/0000000000000002.db".

This works perfectly when I use this path inside my native class's database function as this:

"db=SQLiteDatabase.openDatabase(android.os.Environment.getDataDirectory().toString()+"/data/com.example.hello/app_database/file__0/0000000000000002.db", null, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READWRITE);".

Now here comes the issue. This path works good for android version 4.0.3(API level 15) but gives me a force close for 5.0.1(API 21).

I noticed that phonegap makes a different path for database in 5.0.1 which is as:

"/data/com.example.hello/app_webview/databases/file__0/2"

where 2 is the database file. Is there any solution as how to define our own custom database path for storing database in phonegap, because it is difficult to trace out the path of creation of databases for each API versions and thus use it. Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire