Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用WebView从Google Drive下载PDF文件_Java_Android_Pdf - Fatal编程技术网

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仍然冻结,没有显示任何内容。