Android Webview Err_Unknown_Url_Scheme

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';
}
}


Related Topics



Leave a reply



Submit