如何使用cordova-filechooser在Android上打开文件 [英] How to use cordova-filechooser to open file on Android

查看:506
本文介绍了如何使用cordova-filechooser在Android上打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular和Cordova开发Android应用程序,并且需要通过用户交互打开文件,因此我安装了此Cordova插件

I'm develoing an Android app with Angular and Cordova, and I need to open a file with an user interaction, so I installed this Cordova plugin https://github.com/don/cordova-filechooser

cordova plugin add https://github.com/don/cordova-filechooser.git --save
yarn install

为了使用插件,我编写了这段代码

In order to use plugin i write this code

declare var fileChooser: any;
...
fileChooser.open(function(uri) {
    alert('File is: ' + uri);
});

但是控制台显示未定义fileChooser".

but the console says 'fileChooser is not defined'.

使用此插件的正确方法是什么?

What is the correct way to use this plugin?

科尔多瓦:9.0.0-节点:10.15.0-角度:7.0.4

Cordova: 9.0.0 - Node: 10.15.0 - Angular: 7.0.4

谢谢

推荐答案

  1. 此插件的更新后的分支可以在 https://github.com/ihadeed/cordova-filechooser
  2. 您可能可以将Ionic Native用于Angular,它提供了更多类似于Angular的API: https://ionicionicworkwork.com/docs/native/file-chooser
  3. 否则,您应该可以直接使用fileChooser,因为这是添加到全局作用域中的JS对象(请确保先等待deviceready事件,然后再尝试访问它)
  1. There is a more updated fork of this plugin available at https://github.com/ihadeed/cordova-filechooser
  2. You could probably use Ionic Native for Angular, which gives a more Angular like API: https://ionicframework.com/docs/native/file-chooser
  3. Otherwise you should be able to work with fileChooser directly, as this is the JS object that is added to the global scope (make sure to wait for the deviceready event before trying to access it)

这篇关于如何使用cordova-filechooser在Android上打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆