Abhinaw Tripathi
Abhinaw Tripathi

Reputation: 11

Reading a file using webview?

String googleDocsUrl = "http://docs.google.com/viewer?url="+urlPDF;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");
startActivity(intent);

But it leaves the current activity and it open in google doc url. I want to open it in my current activity in a webview. Please advice and if possible provide an example.

Upvotes: 1

Views: 311

Answers (3)

sumit acharya
sumit acharya

Reputation: 629

    webView = (WebView) findViewById(R.id.webView_medicalpricing);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {

        public void onPageFinished(WebView view, String url) {
            if (mDialog.isShowing()) {
                mDialog.dismiss();
            }
        }

    });
    webView.loadUrl("http://www.google.com");
    return true;

Upvotes: 0

SunnySonic
SunnySonic

Reputation: 1326

you should add something like this to your shouldOverrideUrlLoading:

public boolean shouldOverrideUrlLoading(WebView view, String url) {



        if (url != null )) {
             view.getContext().startActivity(
                 new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
             return true;

        }
            if( url.startsWith("http://docs") || url.startsWith("https:") ) {
                 return false;


            }

Upvotes: 0

Samir Mangroliya
Samir Mangroliya

Reputation: 40416

Simply,

webView.loadUrl(googleDocsUrl);

Upvotes: 1

Related Questions