【发布时间】:2017-02-24 12:04:51
【问题描述】:
我正在使用 cordova-plugin-file-transfer 和插件 cordova-plugin-file-opener2
我可以下载 apk,但我总是遇到这个错误:
错误状态:9 - 错误消息:未找到活动:未找到活动 处理 Intent { act=android.intent.action.VIEW dat=content://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
);
}
【问题讨论】:
-
您的插件似乎没有正确安装。尝试重新安装。
-
不,抱歉尝试了仍然没有运气
-
你能打印出 pathToFile, entry, entry.toURL()... 路径应该类似于 file:///storage/sdcard/download/internalLocalApplication.apk
-
我通过使用更好的插件解决了这个问题。 github.com/Initsogar/cordova-webintent
标签: cordova phonegap-plugins cordova-plugins fileopener2