In my webview I recently implemented the shouldInterceptRequest method to detect when the " link " link is clicked to open it in the android browser instead of opening internally in the webview until it worked the link is opened in the browser but when I go back to the webview application it is also loaded inside it, I would like it to be loaded only in the browser.
My code is as follows:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pb = (findViewById(R.id.pb));
mWebView = findViewById(R.id.webview);
mWebView.setListener(this, this);
mWebView.loadUrl("https://www.sitemercado.com.br/frade");
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Intent i = new Intent(MainActivity.this, off.class);
startActivity(i);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
});
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.sitemercado.com.br/valida")) {
return true;
}
String valida = "https://www.sitemercado.com.br/valida";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(valida));
startActivity(i);
Toast.makeText(getApplicationContext(), "1Detectou", Toast.LENGTH_SHORT).show();
return false;
}
});
Where am I going wrong?