0

I've developed an app for android using Cordova(it's now on playstore) and now implementing autoupdate. Below are the lists of plugin i am using

  1. cordova-plugin-app-version
  2. cordova-plugin-file
  3. cordova-plugin-file-transfer
  4. cordova-plugin-android-permissions
  5. cordova-plugin-file-opener2(I've tried webIntent plugin but that is not working for me).

When i install the downloaded APK, it's getting closed instead of showing me "open screen".

  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var permissions = cordova.plugins.permissions;
    permissions.checkPermission(permissions.WRITE_EXTERNAL_STORAGE, function (status) {
        console.log(status);
        if (!status.hasPermission) {
            var errorCallback = function () {
                console.log("Error: app requires storage permission");
            };
            permissions.requestPermission(permissions.WRITE_EXTERNAL_STORAGE, 
            function (status) { 
                if (!status.hasPermission) 
                    errorCallback(); 
                else { 
                    downloadFile(fileSystem); 
                }
            }, 
            errorCallback); 
        }
        else { 
            downloadFile(fileSystem); 
        }
    }, null); 
    var downloadFile = function (fileSystem) {
    var localPath = 'file:///storage/emulated/0/download/myApp.apk',
    fileTransfer = new FileTransfer();

    fileTransfer.download(encodeURI("URL"), localPath, function (entry){
        cordova.plugins.fileOpener2.open(
            entry.nativeURL, 
            'application/vnd.android.package-archive',
            {
                error : function(e) {
                    console.log('Error status: ' + e.status + ' - Error message: ' + e.message);

                },
                success : function () {

                    console.log('file opened successfully');
                }
            }
        );
        }, function (error) {
            console.log("Error downloading the latest updates! - error: " + JSON.stringify(error));


        });
    };                                      
},function ( evt ) {
    console.log( "Error preparing to download the latest updates! - Err - " + evt.target.error.code );
    message = "Error preparing to download the latest updates, Try again later";
});
Nishant
  • 3
  • 4

1 Answers1

-1

In order to fix this, Are you able to debug exactly which line of your code is ending up in crash ? You can debug with logs locally if you are writing them to file or else you can use tools like crashlytics ( https://try.crashlytics.com/ )

Gayatri
  • 41
  • 6