twillw
twillw

Reputation: 64

WebView opens link, then opens in browser

I have a WebView that is opening a Url for an article. However, a couple of seconds after opening the link in the WebView, the browser opens up and loads the same article. This is my activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_headline_web_view);

Intent intent = getIntent();
Uri headlineUri = intent.getData();

WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadUrl(headlineUri.toString());
}

Thanks in advance!

Upvotes: 0

Views: 180

Answers (1)

cYrixmorten
cYrixmorten

Reputation: 7108

What happens if you add:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_headline_web_view);

    Intent intent = getIntent();
    Uri headlineUri = intent.getData();

    WebView webView = (WebView) findViewById(R.id.webView1);
    webview.setWebViewClient(new MyWebViewClient());
    webView.loadUrl(headlineUri.toString());
}

public class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }
}

Upvotes: 1

Related Questions