gpt4 book ai didi

java - 如何使用 WebView 从 Google Drive 下载 PDF 文件

转载 作者:行者123 更新时间:2023-12-01 18:40:01 27 4
gpt4 key购买 nike

我想从我的驱动器链接下载文件。我不知道该怎么做以及代码是什么。网址是https://drive.google.com/open?id=1txJFXxL9uY3AjyQ3C2G9t9lSkhJqaxuO 。当我尝试这段代码时,我的 WebView 卡住了。

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

最佳答案

尝试一下并检查:

 webView.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(mUrl));
startActivity(i);
}
});

关于java - 如何使用 WebView 从 Google Drive 下载 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59952423/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com