在inAppBrowser - Phonegap / Cordova中启用下载 [英] Enable download in inAppBrowser - Phonegap / Cordova

查看:331
本文介绍了在inAppBrowser - Phonegap / Cordova中启用下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cordova 3.5-0.26& inAppBrowser 0.5.0



现在我在inAppBrowser中加载一个外部页面。有一个下载按钮。当我按下载它不做任何事情。我的事情下载是在inAppBrowser关闭。



然后我尝试使用下面的代码(Android版)来激活下载管理器。

  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);
}
});

这不适用于inAppBrowser。



1)如何在inAppBrowser中启用下载? 2)有没有办法抓住下载与默认下载管理器? 3)如果可能,请提及ios和android的解决方案。如果不是android会做现在。请帮助...

解决方案

InAppBrowser不允许下载。



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



方法名称 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);
}
});

之前 this.inAppWebView.requestFocus();



方法中的相同代码 public void run(){



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

inAppWebView.loadUrl(url); onCreate中的.java文件中的




<$> p $ p> 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);
}
});

不知道iOS


I'm using cordova 3.5-0.26 & inAppBrowser 0.5.0

Now I'm loading an external page in inAppBrowser. There is a download button. When I press the download it doesn't do anything. I thing download is off in inAppBrowser. So as in the cordova view.

Then I tried to active the download manager using following code (for Android)

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);
                    }
                });

This doesn't work for the inAppBrowser either.

1) How can I enable the download in inAppBrowser? 2) Is there any way to catch the download with default download manager? 3) If possible please mention solution for both ios and android. if not android will do for now. Please help...

解决方案

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);
                    }
                });

Don't know about iOS

这篇关于在inAppBrowser - Phonegap / Cordova中启用下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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