使用Google文档在Webview中隐藏pdf的打印/下载选项 [英] Hide Print / download options for pdf in Webview using Google docs

查看:141
本文介绍了使用Google文档在Webview中隐藏pdf的打印/下载选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用Google文档在webview中查看pdf链接时隐藏pdf下载和打印选项.有什么想法可以实现它.我已经尝试过了.

I want to hide the pdf download and print option while viewing the pdf link in webview using Google docs. Is there any idea to achieve it. I've tried this.

mWebView.setWebViewClient(new Callback());

                String urlEncoded = null;
                try {
                    urlEncoded = URLEncoder.encode(url, "UTF-8");
                    url = "http://docs.google.com/viewer?url=" + urlEncoded;

                    Log.d("BrowserACtivity", "doc: "+url);
                    mWebView.loadUrl( url);                   
                } catch (Exception e) {
                    Log.d("BrowserActivity", "Exc: "+e.toString());                
                }

 private class Callback extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return(false);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

            try {
                mWebView.loadUrl("javascript:(function() { " +
                        "document.getElementsByClassName('ndfHFb-c4YZDc-GSQQnc-LgbsSe ndfHFb-c4YZDc-to915-LgbsSe VIpgJd-TzA9Ye-eEGnhe ndfHFb-c4YZDc-LgbsSe')[0].style.display='none'; })()");
            } catch (Exception e) {
                Log.d("BrowserActivity", "onPageFinished -- Exc: " + e.toString());
            }
        }
    } 

但是我无法隐藏它.你能建议我任何想法吗.预先感谢.

But i couldn't hide it. Could you suggest me any idea. Thanks in Advance.

推荐答案

// Enable Javascript
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // Force links and redirects to open in the WebView instead of in a browser
    mWebView.setWebViewClient(new WebViewClient());

    // startWebView("http://google.com");

    mWebView.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));
            String mimeType = null;
            request.setMimeType(mimeType);
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,  URLUtil.guessFileName(url, contentDisposition,mimeType));
            DownloadManager dm = (DownloadManager) getApplicationContext().getSystemService(DOWNLOAD_SERVICE);
            dm.enqueue(request);
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //This is important!
            intent.addCategory(Intent.CATEGORY_OPENABLE); //CATEGORY.OPENABLE
            intent.setType("*/*");//any application,any extension
            Toast.makeText(getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded
                    Toast.LENGTH_LONG).show();

        }
    });

这篇关于使用Google文档在Webview中隐藏pdf的打印/下载选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆