我正在使用cordova-plugin-file-transfer和插件Cordova-plugin-file-opener2
我可以让APK下载,但我一直在遇到这个错误的时间:
错误状态:9-错误消息:找不到活动:找不到活动 处理意图{act = android.intent.action.view dat = content://io.cordova.myappd06b01.opener.provider/external_files/android/data/io.cordova.myappd06b01/files/someapp.apk.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
);
}
i创建示例程序及其工作正常。
<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>
它对我有效。它打开了应用程序下载器。