-1

I am trying to create an android app which will do nothing but would just redirect to the website . Now after opening the app if any button is clicked on it opens up in crome . How to stop that . below is the onCreate() function in my Main Activity class

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.example.com");
//  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);` 

below is the activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Priest
  • 11
  • 6
  • Possible duplicate of [Android webview launches browser when calling loadurl](http://stackoverflow.com/questions/7746409/android-webview-launches-browser-when-calling-loadurl) – mbelsky Feb 28 '16 at 16:08
  • Also you can check the answer to understand reason of this behavior: http://stackoverflow.com/a/9612999/1088836 – mbelsky Feb 28 '16 at 16:10

1 Answers1

0

It works with me.

Add this settings on your webView:

webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new myWebViewClient());
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);

And append this add this private class:

private class myWebViewClient extends WebViewClient {
}