0

私のPhonegap Appから問題は発生しましたが、一度そのファイルをインストールすることはできません。Phonegap WebIntentでダウンロードしたAPKファイルを開く/アクセスできません

次のコードは、APKをインストールする必要があるWEB INTENTセクションでは失敗しますが、ファイルの読み込みには問題があります。だから、cordova-plugin-file-opener2を使用し、Webインテントを取り除くためにpromptForUpdateAndroid()を変更することで、これを考え出し

var apkFilePath = cordova.file.externalApplicationStorageDirectory+'myapp.apk'; 
// Android UPDATE routine 
function downloadApkAndroid(data) { 
    var permissions = cordova.plugins.permissions; 
    permissions.hasPermission(permissions.WRITE_EXTERNAL_STORAGE, function (status) { 
    if (!status.hasPermission) { 
     var errorCallback = function() { 
     alert("Error: app requires storage permission"); 
     if (callBack && callBack !== null) { 
      callBack(); 
     } 
     }; 
     permissions.requestPermission(permissions.WRITE_EXTERNAL_STORAGE, 
     function (status) { 
      if (!status.hasPermission) 
      errorCallback(); 
      else { 
      downloadFile(); 
      } 
     }, 
     errorCallback); 
    } 
    else { 
     downloadFile(); 
    } 
    }, null); 
} 

function downloadFile(){ 
    var fileTransfer = new FileTransfer(); 
    var url = "https://myappurl.com/myapp.apk"; 
    var uri = encodeURI(url); 
    var filePath = getFilePath(); 

    fileTransfer.download(
    uri, 
    apkFilePath, 
    function (entry) { 
     console.log("Download complete: " + entry.fullPath); 
     promptForUpdateAndroid(entry); 
    }, 
    function (error) { 
     console.error("Download error source " + error.source); 
     console.error("Download error target " + error.target); 
     console.error("Download error code " + error.code); 
    }, 
    false, 
    { 

    } 
); 
} 


/* 
* Uses the borismus webintent plugin 
*/ 
function promptForUpdateAndroid(entry) { 
    console.log(apkFilePath); 
    window.plugins.webintent.startActivity(
    { 
     action: window.plugins.webintent.ACTION_VIEW, 
     url: apkFilePath, 
    type: 'application/vnd.android.package-archive' 
    }, 
    function() { 
    }, 
    function() { 
    // alert('Failed to open URL via Android Intent.'); 
    console.log("Failed to open URL via Android Intent. URL: " + entry.fullPath); 
    } 
); 
} 

答えて

0

:それは再度開き、一度インストールされていませんでしたが

var myFilePath = cordova.file.dataDirectory+'myApp.apk'; 

function promptForUpdateAndroid(entry) { 
    cordova.plugins.fileOpener2.open(
    myFilePath, 
    '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'); 
    } 
    } 
); 

これは即座に、アプリをインストールしました。私はそれを理解するためにオフです。

関連する問題