I have an HTML file which is launching an app if I open it in the Android native browser, but when I try to open the same in a WebView, it is not able to launch that application, and "Webpage not available" is shown. I think my WebView is not able to handle the scheme "my.special.scheme://" defined for the application.
I read Launching an Android Application from the Browser, but it does not cover information about launching an app from a WebView.
How do I send a post request in WebView? setWebViewClient(new WebViewClient(){ public void onPageStarted(WebView view, String url, Bitmap favicon) { super. onPageStarted(view, url, favicon); } public boolean shouldOverrideUrlLoading(WebView view, String url) { webView. postUrl(Base_Url, postData.
It's true, links with a custom URI scheme don't load automatically launch apps from a WebView.
What you need to do is add a custom WebViewClient to your WebView:
webView.setWebViewClient(new CustomWebViewClient());
and then in the shouldOverrideUrlLoading(), have the following code:
public boolean shouldOverrideUrlLoading(final WebView webView, final String url) {
if (url.startsWith("my.special.scheme://")) {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
// The following flags launch the app outside the current app
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
return true;
}
return false;
}
I'm not sure, but I believe that WebView simply doesn't handle custom URI schemes.
The workaround is to override WebViewClient.shouldOverrideUrlLoading() and manually test if the URL uses your URI scheme, launching your app and returning true
if it matches, otherwise returning false
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With