使用InAppBrowser从外部网站下载文件-Cordova [英] Download file from external website with InAppBrowser - Cordova

查看:87
本文介绍了使用InAppBrowser从外部网站下载文件-Cordova的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android应用,并且使用 Cordova和AngularJS ...

我想使用 InAppBrowser 打开外部链接,并允许用户从该站点内的链接下载文件...

当我单击应该打开 InAppBrowser 的按钮时,它会打开网站,但是当我单击该网站内的下载链接时,没有任何反应...

该应用具有

 "android.permission.WRITE_EXTERNAL_STORAGE" 

权限

谢谢:)

解决方案

InAppBrowser不允许下载.您将需要修改插件以允许其下载.

对于android,在 platforms \ android \ src \ org \ apache \ cordova \ inappbrowser

方法名称 private void navigation(String url){

包括

  this.inAppWebView.setDownloadListener(new DownloadListener(){公共无效onDownloadStart(String url,String userAgent,字符串contentDisposition,字符串mimetype,long contentLength){意图i =新意图(Intent.ACTION_VIEW);i.setData(Uri.parse(url));cordova.getActivity().startActivity(i);}}); 

在此行之前 this.inAppWebView.requestFocus();

再次在方法 public void run(){

中使用相同的代码

此段之后

  if(clearAllCache){CookieManager.getInstance().removeAllCookie();}否则,如果(clearSessionCache){CookieManager.getInstance().removeSessionCookie();}inAppWebView.loadUrl(url); 

位于onCreate内的.java文件中

  appView.setDownloadListener(new DownloadListener(){公共无效onDownloadStart(String url,String userAgent,字符串contentDisposition,字符串mimetype,long contentLength){意图i =新意图(Intent.ACTION_VIEW);i.setData(Uri.parse(url));startActivity(i);}}); 

添加这两个导入 import android.net.Uri;导入android.webkit.DownloadListener;

不了解iOS

I'm working on android app and I use Cordova and AngularJS...

I want to open external link with InAppBrowser and allow the user to download file from a link inside this site...

When I click the button that should open the InAppBrowser it's opens the website but when I click on download link inside this site, nothing really happens...

The app have

 "android.permission.WRITE_EXTERNAL_STORAGE"

permission

Thanks :)

解决方案

InAppBrowser doesn't allow download. You will need to modify plugin to allow it for downloading.

For android, inside platforms\android\src\org\apache\cordova\inappbrowser

method name private void navigate(String url) {

include

this.inAppWebView.setDownloadListener(new DownloadListener() {
                    public void onDownloadStart(String url, String userAgent,
                            String contentDisposition, String mimetype,
                            long contentLength) {
                      Intent i = new Intent(Intent.ACTION_VIEW);
                      i.setData(Uri.parse(url));
                      cordova.getActivity().startActivity(i);
                    }
                });

before this line this.inAppWebView.requestFocus();

again same code in the method public void run() {

after this segment

if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);

in your .java file inside onCreate

appView.setDownloadListener(new DownloadListener() {
                    public void onDownloadStart(String url, String userAgent,
                            String contentDisposition, String mimetype,
                            long contentLength) {
                      Intent i = new Intent(Intent.ACTION_VIEW);
                      i.setData(Uri.parse(url));
                      startActivity(i);
                    }
                });

add this two import import android.net.Uri; import android.webkit.DownloadListener;

Don't know about iOS

这篇关于使用InAppBrowser从外部网站下载文件-Cordova的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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