我使用cordova-plugin-file-transfer和插件cordova-plugin-file-opener2
我可以让apk下载,但我一直在遇到这个错误:
错误状态:9 - 错误消息:未找到活动:未找到活动 处理Intent {act = android.intent.action.VIEW DAT =含量://io.cordova.myappd06b01.opener.provider/external_files/Android/data/io.cordova.myappd06b01/files/someapp.apk typ = application / vnd.android.package-archive flg = 0x40000000}
var targetPath = encodeURI(cordova.file.externalCacheDirectory + app_name);
var options = {};
var args = {
name: app_name,
url: event.url,
targetPath: targetPath,
options: options
};
downloadReceipt(args);
function downloadReceipt(args) {
var fileTransfer = new FileTransfer();
var uri = encodeURI(args.url);
fileTransfer.download(
uri,
args.targetPath,
function (entry) {
var pathToFile = cordova.file.externalCacheDirectory + args.name;
window.resolveLocalFileSystemURL(pathToFile, function (entry) {
cordova.plugins.fileOpener2.open(
entry.toURL(),
'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 (e) {
console.log('File Not Found');
});
},
function (error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
true,
args.options
);
}
var targetPath = encodeURI(cordova.file.externalCacheDirectory + app_name);
var options = {};
var args = {
name: app_name,
url: event.url,
targetPath: targetPath,
options: options
};
downloadReceipt(args);
function downloadReceipt(args) {
var fileTransfer = new FileTransfer();
var uri = encodeURI(args.url);
fileTransfer.download(
uri,
args.targetPath,
function (entry) {
var pathToFile = cordova.file.externalCacheDirectory + args.name;
window.resolveLocalFileSystemURL(pathToFile, function (entry) {
cordova.plugins.fileOpener2.open(
entry.toURL(),
'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 (e) {
console.log('File Not Found');
});
},
function (error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
true,
args.options
);
}
答案 0 :(得分:0)
我创建示例程序并且工作正常。
<script type="text/javascript">
function clickMe(){
alert("Function called");
cordova.plugins.fileOpener2.open(
'/sdcard/Download/android-debug.apk',
'application/vnd.android.package-archive'
);
}
</script>
<body>
<button onclick="clickMe();">Click Me</button>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>
它对我来说很好。 它打开了应用程序下载程序。