Wednesday, 4 September 2019

Android view .pdf file in web view using redirect url by authenticate user name and password

I would like to view pdf file from share point server. the Url link : https:///sites/iConnect/Lists/FeedList/Attachments/1138/Grasim%20Talent%20Hunt.pdf

it Redirect to the below link: https://login.microsoftonline.com, once I signed in then the response redirect to pdf file url.

In this institution how I handle and view the pdf file to webview.

I tried this code snip:

WebView webView = findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(uri);

webView.setWebViewClient(new WebViewClient()
{
  @Override
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
 {
   if(request.getUrl().toString().endsWith(".pdf")) 
   {
     String weburl = "https://docs.google.com/gview?embedded=true&url=" + request.getUrl().toString();
     view.loadUrl(weburl);
    }
    else
    {
       view.loadUrl(request.getUrl().toString());
    }

    return true;
 }

  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
  }

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

  }

  @Override
  public void onReceivedError(WebView view, int errorCode,String description,String failingUrl) {
//super.onReceivedError(view, request, error);
  Toast.makeText(WebViewActivity.this,"Error"+description, Toast.LENGTH_SHORT).show();
  }


 });

Please suggest if there is any concepts

Thank you

Rajarajan



from Android view .pdf file in web view using redirect url by authenticate user name and password

No comments:

Post a Comment