2

I have made this:

public class Neshaniha extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_neshaniha);

        webView = (WebView) findViewById(R.id.webview);
        webView.loadUrl("http://www.mywebsite.org/");

    }


}

But if i open links in this app, its opening in the browser, not in the app. How can i made this?

Thanx.

Marv
  • 33
  • 11

2 Answers2

1

Use WebViewClient for your Webview.

MithunRaj
  • 543
  • 2
  • 7
  • 19
1

just use it

   WebView webviewGoogle;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.news);

    webviewGoogle= (WebView)findViewById(R.id.site_news);
    webView();
}

private void webView(){
    webviewGoogle.getSettings().setJavaScriptEnabled(true);
    webviewGoogle.setWebViewClient(new MyWebViewClient());
    webviewGoogle.setWebViewClient(new WebViewClient());
    webviewGoogle.loadUrl("http://www.google.com/");
}

@Override public void onBackPressed() {
    if(webviewGoogle.canGoBack()) {
        webviewGoogle.goBack();
    } else {
        super.onBackPressed();
    }
}

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("http://www.google.com/")) { 
            return false;
        }
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }
}