In fact, WebView is not able to work with URL schemes, such as mailto, tg, sms, phone. You must override the shouldOverrideUrlloading () method and do what your web view needs when this type of circuit is found.
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if( URLUtil.isNetworkUrl(url) ) { return false; } try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); }catch(ActivityNotFoundException e) { Log.e("AndroiRide",e.toString()); Toast.makeText(MainActivity.this,"No activity found",Toast.LENGTH_LONG).show(); } return true; }
shouldOverrideUrlLoading (WebView, String URL) is deprecated at API level 24.
Therefore, override the public logical shouldOverrideUrlLoading (WebView, WebResourceRequest request)
@RequiresApi(Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { String url=request.getUrl().toString(); if( URLUtil.isNetworkUrl(url) ) { return false; } try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); }catch(ActivityNotFoundException e) { Log.e("AndroiRide",e.toString()); Toast.makeText(MainActivity.this,"No activity found",Toast.LENGTH_LONG).show(); } return true; }
Customize the code if you are creating your own schemas. [ ERR unknown URL scheme in Android WebView - Kotlin & Java code]
source share