StonebridgeGR
StonebridgeGR

Reputation: 11

How can I open a web page from inside my app?

I've found an app's source code and it opens web pages using external browsers, like Chrome or others. I want to make it access those pages from inside the app, without using an external browser. I think that I should change the code below somehow, but I don't know how.

private class MyWebviewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("http://dmc.teiion.gr")) {
            //open url contents in webview
            return false;
        } else {
            //here open external links in external browser or app
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }

Upvotes: 0

Views: 631

Answers (1)

ahmed mahmoud
ahmed mahmoud

Reputation: 192

Use:

yourWebView.setWebViewClient(new WebViewClient(){

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

Or change:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);

to

view.loadUrl(url);

Upvotes: 2

Related Questions