android - shared SQl Lite db between phonegap app and native java app -


i have 2 android apps (one written in js(using phonegap) other in java). both need access 1 sqlite db. yes it's possible.

in js file use cordova-sqlite-storage create , insert data db:

var db = window.sqliteplugin.opendatabase({name: "cac.db", location: 1});                                      db = sqliteplugin.opendatabase({name: "cac.db", location: 2, createfromlocation: 1});                                             db.transaction(function(tx) {                                             tx.executesql('drop table if exists test_table');                                             tx.executesql('create table if not exists test_table (id integer primary key, data text, data_num integer)');                                              // demonstrate pragma:                                             db.executesql("pragma table_info (test_table);", [], function(res) {                                               console.log("pragma res: " + json.stringify(res));                                             });                                              tx.executesql("insert test_table (data, data_num) values (?,?)", ["my id", 100], function(tx, res) {                                                 db.transaction(function(tx) {                                                   tx.executesql("select data dt test_table;", [], function(tx, res) {                                                   var id = res.rows.item(0).dt;                                                   console.log("res.rows.item(0).cnt: " + id);                                                  });                                               });                                              }, function(e) {                                               console.log("error: " + e.message);                                             });                                           }); 

then use this answer try connect java app preexisting db:

 context sharedcontext = null;                         try {                             sharedcontext = this.createpackagecontext("com.my.app", context.context_include_code);                             if (sharedcontext == null) {                                 return;                             }                         } catch (exception e) {                             string error = e.getmessage();                             return;                         }                          dbadapter shareddbadapter = new performerdbadapter(sharedcontext);                         shareddbadapter.open(); 

however required use code in js app:

dbadapter hostdbadapter = new dbadapter(getapplicationcontext()); performerdbadapter.open(); 

to try context. (but can't because code^ java). tried context using this answer.(context context=this.cordova.getactivity().getapplicationcontext();) not sure add this, , not sure if code work anyways.

my questions are:

  1. where add this code in application?
  2. am on right path?
  3. what best way connect js app , java app same sqlite dtatabase on android? (examples helpful)

info:

android 5.1, cordova 5.0

update:

i have android:shareduserid="my.app" in both apps.

1) depends application, please read book on android , able put code need. can use greendao more simple access sqlite

3) can sign 2 different app same certificate, in way 2 apps recognised "same user id" , can share private data

2) way, way (the best way) expose data between 2 app on android use content provider

i hope you


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -