私はそれの中にウェブサイトを読み込む単一のWebViewを使用するアンドロイドアプリケーションを持っています。Android WebviewダウンロードマネージャーPDFファイルをダウンロードする
setContentView(R.layout.activity_main);
WebView webView = (WebView) this.findViewById(R.id.webview);
は、その後私は、ウェブサイトのHTMLの代わりに、PDFをダウンロードしてもらうウェブサイトによって動的に作成されたファイルをダウンロードしようとすると、サーバー
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
// ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
//for downloading directly through download manager
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
Environment.getExternalStorageDirectory();
getApplicationContext().getFilesDir().getPath(); //which returns the internal app files directory path
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
から私のファイルをダウンロードするためにダウンロードマネージャを使用しました。 HTMLページは、認証のためのログインページが表示されていることをアドバンス実際
onDownloadListenerに3行を追加する必要がありますか? – Shadow