Sunday, February 22, 2015

Load URL in WebView Android

Open URL in WebView:

In android open website by using WebView. WebView use for display website content in android like as browser.

What is WebView:

WebView use for open website in android like browser. WebView display all website data in andriod.
Like this URL open in WebView http://invokecode.blogspot.in/

WebView in Android
WebView in Android


Open URL in WebView:

simple open url in websview 
webview.loadUrl("url");
but when click on any link in this page then it open in browser and not open in this webview so we use WebViewClient  for  open in same webview like website

Why URL Open in Default Browser:

as we discuss url open in default browser not open in websview like website as show in pic.

Open URL in Default Browser
URL Open in Default Browser

Open Link in Same WebView:

open URL in same webview then use WebViewClient. by extend and it has @Override Mothod basically Three Metho called 
onPageStarted
shouldOverrideUrlLoading(load URL)
onPageFinished(Load URL Complete and it finish)

  webView.setWebViewClient(new webViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://invokecode.blogspot.in/");

    public class webViewClient extends WebViewClient
   {
       @Override
       public void onPageStarted(WebView view, String url, Bitmap favicon) {
           // TODO Auto-generated method stub
           super.onPageStarted(view, url, favicon);
       }

       @Override
       public boolean shouldOverrideUrlLoading(WebView view, String url) {
           // TODO Auto-generated method stub
           view.loadUrl(url);
           return true;
       }

       @Override
       public void onPageFinished(WebView view, String url) {
           // TODO Auto-generated method stub
           super.onPageFinished(view, url);
  // if use Progress Dialog then Dismiss Here
       }
   }

above code for view complete website in WebView, now when load website and show Doload or some Progress Bar that use wait and load website then it hide lke that:

Show Dialog in WebView:

show dialog in webview  onPageStarted  Method show dialog and dismiss in  onPageFinished:
Show Dialog in WebView
Show Dialog in WebView

Note: if any issue to implement this code or need help related this tutorial Please comments I will revert back.

For More Turorials Visit:  http://invokecode.com/
Like Us On Facebook:  InvokeCode

Thank You !!

15 comments :

  1. wow thats a great tutorial for newbie's

    ReplyDelete
  2. Nice to see step by step process to load URL in WebView in android app. Being an active member of many android developer forum, I am looking to learn such tips. It really rocks.

    ReplyDelete
  3. It is really a great work and the way in which u r sharing the knowledge is excellent.

    ReplyDelete
  4. It is really nice information is very relevant and the way of sharing the knowledge is excellent.

    ReplyDelete
  5. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in Chennai | rpa training in pune

    rpa online training | rpa training in bangalore

    ReplyDelete
  6. I know you feel more happy when you get things done and best of all those things are your most precious treasure.
    python training in tambaram
    python training in annanagar
    python training in OMR
    python training in chennai

    ReplyDelete
  7. Well researched article and I appreciate this. The blog is subscribed and will see new topics soon.
    java online training | java training in pune

    java training in chennai | java training in bangalore

    ReplyDelete
  8. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    Oracle Training in Chennai | Best Oracle Training Institute in Chennai
    Web Design Training in Chennai
    Web Design Training in Chennai|Best Web Design Training in Chennai
    AngularJS Training in Chennai |Advanced SAS Training in Chennai | Best SAS Training in Chennai


    ReplyDelete