简体   繁体   English

下载链接在android浏览器应用中不起作用

[英]Download link not working in android browser app

Recently I created a simple Android browser app for my website. 最近,我为我的网站创建了一个简单的Android浏览器应用程序。 Everything is working fine but when I click on the download link it does not start downloading. 一切正常,但是当我单击下载链接时,它没有开始下载。 Its .apk file is stored inside my server. 它的.apk文件存储在我的服务器中。

Downloading is working fine in other browsers like Chrome, Android browser and all others. 在其他浏览器(例如Chrome,Android浏览器和所有其他浏览器)中,下载工作正常。

Here is my main-activity code. 这是我的主要活动代码。

{
    setContentView(R.layout.activity_main);
    WebView ourBrow = (WebView) findViewById(R.id.webviewapkapps);
    ourBrow.setWebViewClient(new OurViewClient());
    ourBrow.loadUrl("http://websitename .com");
    ourBrow.getSettings().setJavaScriptEnabled(true);
}

Adding DownloadListener will help you! 添加DownloadListener将为您提供帮助!

 {
        setContentView(R.layout.activity_main);
        WebView ourBrow = (WebView) findViewById(R.id.webviewapkapps);
        ourBrow.setWebViewClient(new OurViewClient());
        ourBrow.loadUrl("http://websitename .com");
        ourBrow.getSettings().setJavaScriptEnabled(true);
      ourBrow.setDownloadListener(new DownloadListener() {
                public void onDownloadStart(String url, String userAgent,
                                String contentDisposition, String mimetype,
                                long contentLength) {

                                              Uri uri = Uri.parse(url);
               Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                        startActivity(intent);
                }
    }

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

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