Java 如何使用WebView从Google Drive下载PDF文件
我想从我的驱动器链接下载一个文件。 我不知道怎么做,代码是什么。 网址是。 当我尝试这段代码时,我的网络视图冻结了Java 如何使用WebView从Google Drive下载PDF文件,java,android,pdf,Java,Android,Pdf,我想从我的驱动器链接下载一个文件。 我不知道怎么做,代码是什么。 网址是。 当我尝试这段代码时,我的网络视图冻结了 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wvnpwpop); //Webview WebView webView = findViewById(R
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);
}
});
您可能需要登录。查找要登录的url并重定向到您的gdrive distination我尝试了,但结果仍然相同,webView仍然冻结,没有显示任何内容。