0

I am trying to get Web View current URL in dialog box.

I used following code, but its giving error

String webUrl1 = web.getUrl();
builder.setMessage(webUrl1);

here is full code.

i am trying to match url in if condition. but it doesn't giving any error nor working properly.

    //setting up web view
    setContentView(R.layout.main);
    web = (WebView) findViewById(R.id.webView1);
    setUpWebView();
    web.loadUrl("http://www.example.com");

    String webUrl1 = web.getUrl();

    if (webUrl1=="http://www.example.com"){
    //do something.
    }
Cœur
  • 34,719
  • 24
  • 185
  • 251
FAAD
  • 79
  • 3
  • 13

1 Answers1

0

That's not how we compare strings in java. Change this

if (webUrl1=="http://www.example.com"){

with

if (webUrl1.equalsIgnoreCase("http://www.example.com")){
Cœur
  • 34,719
  • 24
  • 185
  • 251
Rohit5k2
  • 17,529
  • 8
  • 42
  • 56