0

I have a native android app in which there are two activities, 1st activity contains a button and on action of button I want to start the 2nd activity. Content of seconds activity will be from a website. Is it possible to make the 2nd activity behave like webapp ?

If I use WebView in this case, it is displaying the website inside the activity but when I try to interact with the website, it ask to open it in the browser which I don't want. I want to interact with the website within the activity.

Any help will be highly appreciated. Thanks a ton.

Vipul J
  • 6,641
  • 9
  • 46
  • 61

3 Answers3

1

Use below code... for open link in WebView itself instead of browser...

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view);       
    WebView engine = (WebView) findViewById(R.id.web_view);
    engine.loadUrl("https://play.google.com/store?hl=en");
    engine.setWebViewClient( new HelloWebViewClient() );
} 



 private class HelloWebViewClient extends WebViewClient {

  @Override
  public boolean shouldOverrideUrlLoading( WebView view, String url ) {                 

     return false;
  }
}

see this link for more details... WebView should not open links in browser

Community
  • 1
  • 1
Priyank Patel
  • 12,244
  • 8
  • 65
  • 85
0

I think if you set the baseURL property when creating the Webview, you'll get what you want.

Philippe Girolami
  • 1,876
  • 1
  • 13
  • 15
  • First of all thanks for replying. But I use WebView in this case, it is displaying the website inside the activity but when I try to interact with the website, it ask to open it in the browser which I don't want. I want to interact with the website within the activity. – Vipul J Oct 05 '12 at 08:29
0

Create you're own Webview where you can override the default behaviour:

private class CustomWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}
D-32
  • 3,245
  • 2
  • 22
  • 33
  • But how would I know the url which the user is requesting after baseurl ? For example - At first, I can load the base url in the webview, then user clicks a button in the website. Now how would I know the url of the page which button refers to ? – Vipul J Oct 05 '12 at 08:39
  • I'm not sure, as I can't test it at the moment, but I would think that in the method above (shouldOverrideUrlLoading) the parameter "url" is the url the link / button links to. Did you try it out? – D-32 Oct 05 '12 at 09:11