I have a simple webview app that stats with a splash screen. As it goes to the MainActivity it will open in Chrome but only while on mobile data. If on wifi it opens in the app. Opening in the app is the intended action. How can I force the page to open in my webview regardless of connection type? See my code below...
Note: links clicked within the webview open in Chrome, which is the intended action.
I hope I was clear enough, I've only been developing apps for a month or so. Thanks! I really appreciate the help!
public class MainActivity extends AppCompatActivity implements AdvancedWebView.Listener {
private AdvancedWebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (AdvancedWebView) findViewById(R.id.webview);
mWebView.setListener(this, this);
mWebView.loadUrl("http://seanpattersondesigns.com");
boolean preventCaching = false;
mWebView.setGeolocationEnabled(true);
mWebView.loadUrl("http://seanpattersondesigns.com", preventCaching);
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("http://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
}
@SuppressLint("NewApi")
@Override
protected void onResume() {
super.onResume();
mWebView.onResume();
}
@SuppressLint("NewApi")
@Override
protected void onPause() {
mWebView.onPause();
super.onPause();
}
@Override
protected void onDestroy() {
mWebView.onDestroy();
super.onDestroy();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
mWebView.onActivityResult(requestCode, resultCode, intent);
}
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
finish();
}
}
@Override
public void onPageStarted(String url, Bitmap favicon) {
}
@Override
public void onPageFinished(String url) {
}
@Override
public void onPageError(int errorCode, String description, String failingUrl) {
}
@Override
public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
}
@Override
public void onExternalPageRequest(String url) {
}
}