How to download and rewrite database sqlite in android device?

I build and run application in android device. My application use ng-cordova in ionic framework.In service.js , I have

 $rootScope.db = $cordovaSQLite.openDB("MyApp.db"); 

And at here, i don’t know path of database sqlite in android device ,
I open android device ,and discovery at Internal
folder and files folder . I can not see database MyApp.db.
The problem in here , i want to download new database and rewrite old
database, but i don’t know direct path of database . In controller.js

 $scope.downloadFileDB = function () {
    var url = "";
    var filename = url.split("/").pop();
    //var targetPath = cordova.file.externalRootDirectory + "/Android/data/com.ionicframework.myapp596823/files/" + filename;
    //var targetPath = cordova.file.externalRootDirectory + filename;
    //var targetPath = cordova.file.dataDirectory + filename;

    var trustHosts = true
    var options = {};
    $, targetPath, options, trustHosts)
      .then(function (result) {
          alert("Success " + JSON.stringify(result));
      }, function (error) {
          alert("Error " + JSON.stringify(error));
      }, function (progress) {
          $timeout(function () {
              $scope.downloadProgress = (progress.loaded / * 100;

If you know path of database , tell me.Thank you so much.

I think you can’t… you can ship your app with a preloaded db, then you can sync app db with an external db.

1 Like

Dear @fabioferrero ,
Can you give me some reference links how to implement it ? Step by step about this , I looking for some days :joy: .According you say, I think it would be like this

  1. Download database from server ( to SDcard in android device or internal Storage
  2. Sync data : select all data in table of database, which new download , insert to application database
  3. Delete database , which download
    If something wrong or mistake , please tell me
    Thank you so much.

Can you detail this ?
Thank you so much.

You can start with this:

Oh, I had tested it, It attach database to app.
In here i want to update database of app, example: download database and rewrite or sync-data , or using JSON as you say .