简体   繁体   English

在Phonegap中使用inappbrowser无法使用downlad文件?

[英]Not able to downlad file using inappbrowser in Phonegap?

I Create an App where download a file from server in mobile, so I Use InAppBrowser plugin to open download page link, its working fine but i am not able to download file using my app, when i open download link in mobile browser its automatic start download. 我创建一个应用程序从移动服务器下载文件,所以我使用InAppBrowser插件打开下载页面链接,其工作正常但我无法使用我的应用程序下载文件,当我在移动浏览器中打开下载链接时它自动启动下载。

please help me thanks in advance. 请提前帮助我。

I think, its better to open system browser using inAppBrowser plugin for both the platform by using 我认为,最好使用inAppBrowser插件为这两个平台打开系统浏览器

    window.open('http://apache.org', '_system', 'location=yes');

using this you can easily download. 使用这个你可以轻松下载。

InAppBrowser doesn't allow download. InAppBrowser不允许下载。 You will need to modify plugin to allow it for downloading. 您需要修改插件才能下载。

For android, inside platforms\\android\\src\\org\\apache\\cordova\\inappbrowser 对于android,内部platforms\\android\\src\\org\\apache\\cordova\\inappbrowser

method name private void navigate(String url) { 方法名称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(); 在此行之前this.inAppWebView.requestFocus();

again same code in the method public void run() { 方法中的相同代码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 在onCreate里面的.java文件中

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 不了解iOS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM