Android Webview net::ERR_UNKNOWN_URL_SCHEME Error To Play Store
This error is appeared because the WebView can’t recognize the special URL Scheme,
for example, the WebView will usually recognize http and https, anything other than these, for example – intent://, market://, app://, mail:// , whatsapp:// etc will not be recognized by WebView unless we add a handler to handle these url schemes, or by disabling these schemes and only load http and https schemes.
The Code to Fix err_unknown_url_scheme intent://
webview.setWebViewClient(new WebViewClient() {
String currentUrl;
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
currentUrl = url;
if (url.startsWith("http") || url.startsWith("https")) {
return false;
}
if (url.startsWith("intent")) {
try {
Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
String fallbackUrl = intent.getStringExtra("browser_fallback_url");
if (fallbackUrl != null) {
webview.loadUrl(fallbackUrl);
return true;
}}
catch (URISyntaxException e) {
//not an intent uri
}
return true;//do nothing in other cases
}
fix net::err_unknown_url_scheme whatsapp link on flutter webview
First, add url_launcher, then I use this code to launch whatsapp on flutter webview and works.
WebView(
initialUrl: getUrl(_url),
javascriptMode: JavascriptMode.unrestricted,
navigationDelegate: (NavigationRequest request) async {
if (request.url
.startsWith('https://api.whatsapp.com/send?phone')) {
print('blocking navigation to $request}');
List<String> urlSplitted = request.url.split("&text=");
String phone = "0123456789";
String message =
urlSplitted.last.toString().replaceAll("%20", " ");
await _launchURL(
"https://wa.me/$phone/?text=${Uri.parse(message)}");
return NavigationDecision.prevent;
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},
)
_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Open Native Apps in WebApp net::ERR-UNKNOWN-URL-SCHEME
OK, so, to start a call after clicking on a link in your WebView, you would first create a link with this type of scheme:
<a href=\"tel:8056542739\">(805) 654-2739.</a>
Then, in your code, you would override shouldOverrideUrlLoading() like this:
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView wView, String url)
{
if (url.startsWith("mailto:") || url.startsWith("tel:") || url.startsWith("geo:") || url.startsWith("http:") || url.startsWith("https:")) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);
return true;
} else if (url.startsWith("whatsapp:")) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
return true;
} else if (url.startsWith("spotify:")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
"spotify:album:0sNOF9WDwhWunNAHPD3Baj"));
intent.putExtra(Intent.EXTRA_REFERRER,
Uri.parse("android-app://" + context.getPackageName()));
startActivity(intent);
return true;
}
return false;
}
});
This override sends anything with a tel:, mailto:, http: or https: scheme to a new 'intent' with ACTION_VIEW, which means that Android will try to find one or more apps installed on the device that can handle that kind of URI. The Phone app can handle tel: so, that gets called if your link has that scheme in it, like my example. Same thing for the mailto: scheme, that should open your e-mail composing app. For whatsapp and spotify, they both have schemes such as whatsapp: and spotify: which can be handled slightly differently. See one possible way above for that.
Related Topics
How to Get Preview in Composable Functions That Depend on a View Model
How to Know Whether a Recyclerview/Linearlayoutmanager Is Scrolled to Top or Bottom
How to Perform Minification and Obfuscation with the Jack Compiler
Android Add Image to Webview from a Drawable
Are There Conventions on How to Name Resources
How to Bring a Background Task to The Front Below Honeycomb
How to Set The Font Style to Bold, Italic and Underlined in an Android Textview
Overriding the Power Button in Android
Error: This Android Sdk Requires Android Developer Toolkit Version 22.6.1 or Above
How to Add Network_Security_Config.Xml to Manifest in Expo App Without Ejecting
Android Httpclient File Upload Data Corruption and Timeout Issues
How to Get Screen Display Metrics in Application Class
Bottomsheetdialog with Transparent Background
Android Attaching Multiple Adapters to One Adapter
Android Device Configuration for Aosp
Put an Indeterminate Progressbar as Footer in a Recyclerview Grid