【问题标题】:Cordova - fileOpener2 - Activity not found: No Activity found to handle IntentCordova - fileOpener2 - 找不到活动:找不到处理意图的活动
【发布时间】: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


【解决方案1】:

我创建了示例程序并且它工作正常。

<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>

它对我来说很好用。 它打开了应用程序下载器。

【讨论】:

  • 我相信该问题已在脚本中得到解决。我与 github 上的开发人员就该错误进行了通信。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-18
  • 2013-08-24
相关资源
最近更新 更多