下载开始并显示应用程序后如何关闭 WebBrowser?

How to close the WebBrowser once the download starts and shows the app?

我正在使用 intent 从我的 android 应用程序将我的 URL 传递给 WebBrowser 以下载文件。但是一旦下载开始,它就会停留在 WebBrowser。所以我想在下载开始后关闭 WebBrowser 并显示应用程序。

这是我用来传递 URL:

的代码
js hide: false console: true babel:

} else if (tabId == R.id.tab_b) {
    webView.loadUrl("file:///android_asset/D.html");
    webView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            Toast.makeText(getApplicationContext(), "Downloading File",   To notify the Client that the file is being downloaded
            Toast.LENGTH_LONG).show();
            startActivity(intent);
        }
    });
}

最后,如果可能的话,我可以不打开 WebBrowser 下载我的应用程序吗?

强制下载:

 webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String aUrl, String userAgent, String contentDisposition, String mimetype, long contentLength) {


                    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(aUrl));
                    request.allowScanningByMediaScanner();
                    CookieManager cookieManager = CookieManager.getInstance();
                    String cookie = cookieManager.getCookie(aUrl);
                    request.addRequestHeader("Cookie", cookie);
                    request.addRequestHeader("User-Agent", userAgent);
                    Environment.getExternalStorageDirectory();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
                    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                    dm.enqueue(request);
                    registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));





        }


});

并且不要忘记添加这些方法以在下载后打开 pdf:

BroadcastReceiver onComplete=new BroadcastReceiver() {
        public void onReceive(Context ctxt, Intent intent) {
// HERE YOU ADD WHAT YOU WANT AFTER DONWLOAD     
 }
            };

另外不要忘记在 :

中声明权限
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />