Source

Target

Commits (1)
  • Vincas Dargis's avatar
    Android: add support for various url schemes. · 70cc7914
    Vincas Dargis authored
    
    Android WebView does not handle schemes by default, such
    as mailto:, geo:, and others, but will instead show an
    "ERR_UNKNOWN_URL_SCHEME" error. This patch fixes it by
    starting ACTION_VIEW Intent for specified scheme, meanwhile
    showing the same "ERR_UNKNOWN_URL_SCHEME" error page for
    invalid cases as before.
    
    [ChangeLog][Android] Added support for various url schemes.
    
    Taks-number: QTBUG-53736
    Change-Id: Ib569ec1598f76f823b2293446ea4e513764ef1fa
    Reviewed-by: default avatarChristian Stromme <christian.stromme@qt.io>
    70cc7914
Showing with 22 additions and 0 deletions
......@@ -39,12 +39,15 @@ package org.qtproject.qt5.android.view;
import android.content.pm.PackageManager;
import android.view.View;
import android.webkit.GeolocationPermissions;
import android.webkit.URLUtil;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import java.lang.Runnable;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import java.lang.String;
import android.webkit.WebSettings;
import android.util.Log;
......@@ -105,6 +108,25 @@ public class QtAndroidWebViewController
{
QtAndroidWebViewClient() { super(); }
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// handle http: and http:, etc., as usual
if (URLUtil.isValidUrl(url))
return false;
// try to handle geo:, tel:, mailto: and other schemes
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public void onLoadResource(WebView view, String url)
{
......