Я хочу скачать файл по ссылке на диске. Я не знаю, как это сделать и каков код. URL-адрес https://drive.google.com/open?id=1txJFXxL9uY3AjyQ3C2G9t9lSkhJqaxuO. Когда я пробую этот код, мой WebView go зависает.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wvnpwpop);
//Webview
WebView webView = findViewById(R.id.wvnpwpop);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://drive.google.com/open?id=1txJFXxL9uY3AjyQ3C2G9t9lSkhJqaxuO");
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
DownloadManager.Request request = new DownloadManager.Request( Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "myPDFfile.pdf");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
//WebSettings
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
// -------- End Of WebView and Web Settings