Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display URL in WebView

In my JsonParsing and i got the url from this json. I need to display that Url link as in webview. How should i do that?

Code is here:

     TextView tv = (TextView)findViewById(R.id.textView1);
     Bundle bundle = new Bundle();
     bundle  = getIntent().getExtras();

           String id = bundle .getString("id");
           String firstName = bundle.getString("firstName");
           String lastName = bundle.getString("lastName");
           String headline = bundle.getString("headline");
           String pictureUrl = bundle.getString("pictureUrl");
           String url = bundle.getString("url");


          Log.v("LV","id :"+id+"\n"+"firstname :"+firstName+"\n"+"lastname :"+lastName+"\n"+"headline :"+headline+"\n"+"pictureUrl :"+pictureUrl+"\n"+"siteStandardProfileRequest"+url);
          tv.setText("id :"+id+"\n"+"firstname :"+firstName+"\n"+"lastname :"+lastName+"\n"+"headline :"+headline+"\n"+"pictureUrl :"+pictureUrl+"\n"+"Profile URL :"+url);   
like image 270
user3886658 Avatar asked Aug 05 '14 07:08

user3886658


2 Answers

as you have ask for url open in webview so you have to take one webview in your project and do like this

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);

// you need to setWebViewClient for forcefully open in your webview 
webview.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
});

and other way is (this will open in web browser)

Intent browserIntent = new Intent(Intent.ACTION_VIEW,uri.parse(url));
startActivity(browserIntent);
like image 115
MilapTank Avatar answered Oct 04 '22 04:10

MilapTank


Use This Code:

   webView = (WebView) findViewById(R.id.webView1);
   progressDialog = ProgressDialog.show(MainActivity.this, "", "Loading...",true);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.getSettings().setAllowFileAccess(true);

    webView.loadUrl("http://example.com/shidhin/test.html"); // Here You can put your Url
    webView.setWebChromeClient(new WebChromeClient() {
    });

    webView.setWebViewClient(new WebViewClient() {
             public boolean shouldOverrideUrlLoading(WebView view, String url) {
                 return false;
            }
            public void onPageFinished(WebView view, String url) {
               progressDialog.dismiss();
               //Toast.makeText(context, "Page Load Finished", Toast.LENGTH_SHORT).show();
            }
      });        
like image 30
SHIDHIN.T.S Avatar answered Oct 04 '22 03:10

SHIDHIN.T.S