@@ -21,6 +21,8 @@ Licensed to the Apache Software Foundation (ASF) under one
2121import android .annotation .SuppressLint ;
2222import android .content .Context ;
2323import android .content .Intent ;
24+ import android .content .pm .PackageManager ;
25+ import android .content .pm .ResolveInfo ;
2426import android .graphics .Color ;
2527import android .provider .Browser ;
2628import android .content .res .Resources ;
@@ -412,7 +414,7 @@ public String openExternal(String url) {
412414 intent .putExtra (Browser .EXTRA_APPLICATION_ID , cordova .getActivity ().getPackageName ());
413415 this .cordova .getActivity ().startActivity (intent );
414416 return "" ;
415- // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
417+ // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
416418 } catch (java .lang .RuntimeException e ) {
417419 LOG .d (LOG_TAG , "InAppBrowser: Error loading url " +url +":" + e .toString ());
418420 return e .toString ();
@@ -593,7 +595,7 @@ public String showWebPage(final String url, HashMap<String, Boolean> features) {
593595 }
594596 Boolean wideViewPort = features .get (USER_WIDE_VIEW_PORT );
595597 if (wideViewPort != null ) {
596- useWideViewPort = wideViewPort .booleanValue ();
598+ useWideViewPort = wideViewPort .booleanValue ();
597599 }
598600 }
599601
@@ -608,8 +610,8 @@ public String showWebPage(final String url, HashMap<String, Boolean> features) {
608610 */
609611 private int dpToPixels (int dipValue ) {
610612 int value = (int ) TypedValue .applyDimension ( TypedValue .COMPLEX_UNIT_DIP ,
611- (float ) dipValue ,
612- cordova .getActivity ().getResources ().getDisplayMetrics ()
613+ (float ) dipValue ,
614+ cordova .getActivity ().getResources ().getDisplayMetrics ()
613615 );
614616
615617 return value ;
@@ -645,7 +647,7 @@ public void run() {
645647 int toolbarColor ;
646648 int blackColor = android .graphics .Color .rgb (0 , 0 , 0 );
647649 int accentColor = android .graphics .Color .rgb (190 , 255 , 26 ); //android.graphics.Color.rgb(0, 122, 255);
648- if (Build .VERSION .SDK_INT >= 21 ){
650+ if (Build .VERSION .SDK_INT >= 21 ){
649651 /*
650652 toolbarColor = cordova.getActivity().getWindow().getStatusBarColor();
651653 dialog.getWindow().setStatusBarColor(toolbarColor); //TODO: not working
@@ -705,8 +707,8 @@ public void onClick(View v) {
705707 edittext .setBackgroundColor (android .graphics .Color .WHITE );
706708 edittext .setTextColor (blackColor );
707709 }
708- edittext .setTextSize (12 );
709- edittext .setPadding (this .dpToPixels (8 ), this .dpToPixels (4 ), this .dpToPixels (8 ), this .dpToPixels (4 ));
710+ edittext .setTextSize (12 );
711+ edittext .setPadding (this .dpToPixels (8 ), this .dpToPixels (4 ), this .dpToPixels (8 ), this .dpToPixels (4 ));
710712 edittext .setGravity (Gravity .CENTER );
711713 edittext .setSingleLine (true );
712714 edittext .setTextAlignment (View .TEXT_ALIGNMENT_CENTER );
@@ -892,8 +894,8 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
892894 WebSettings settings = inAppWebView .getSettings ();
893895 settings .setJavaScriptEnabled (true );
894896 settings .setJavaScriptCanOpenWindowsAutomatically (true );
895- settings .setBuiltInZoomControls (true );
896- settings .setDisplayZoomControls (showZoomControls );
897+ settings .setBuiltInZoomControls (true );
898+ settings .setDisplayZoomControls (showZoomControls );
897899 settings .setPluginState (android .webkit .WebSettings .PluginState .ON );
898900
899901 settings .setMediaPlaybackRequiresUserGesture (mediaPlaybackRequiresUserGesture );
@@ -1141,7 +1143,24 @@ public InAppBrowserClient(CordovaWebView webView, TextView mEditText) {
11411143 /**
11421144 * Override the URL that should be loaded
11431145 *
1144- * This handles a small subset of all the URIs that would be encountered.
1146+ * New (added in API 24)
1147+ * For Android 7 and above.
1148+ *
1149+ * @param webView
1150+ * @param request
1151+ */
1152+ /*@TargetApi(Build.VERSION_CODES.N)
1153+ @Override
1154+ public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest request) {
1155+ //TODO: handle request.getMethod()
1156+ return shouldOverrideUrlLoading(webView, request.getUrl().toString());
1157+ }*/
1158+
1159+ /**
1160+ * Override the URL that should be loaded
1161+ *
1162+ * Legacy (deprecated in API 24)
1163+ * For Android 6 and below.
11451164 *
11461165 * @param webView
11471166 * @param url
@@ -1157,7 +1176,7 @@ public boolean shouldOverrideUrlLoading(WebView webView, String url) {
11571176 } catch (android .content .ActivityNotFoundException e ) {
11581177 LOG .e (LOG_TAG , "Error dialing " + url + ": " + e .toString ());
11591178 }
1160- } else if (url .startsWith ("geo:" ) || url .startsWith (WebView .SCHEME_MAILTO ) || url .startsWith ("market:" ) || url . startsWith ( "intent:" ) ) {
1179+ } else if (url .startsWith ("geo:" ) || url .startsWith (WebView .SCHEME_MAILTO ) || url .startsWith ("market:" )) {
11611180 try {
11621181 Intent intent = new Intent (Intent .ACTION_VIEW );
11631182 intent .setData (Uri .parse (url ));
@@ -1166,9 +1185,33 @@ public boolean shouldOverrideUrlLoading(WebView webView, String url) {
11661185 } catch (android .content .ActivityNotFoundException e ) {
11671186 LOG .e (LOG_TAG , "Error with " + url + ": " + e .toString ());
11681187 }
1169- }
1188+ } else if (url .startsWith ("intent:" )) {
1189+ try {
1190+ Context context = cordova .getActivity ();
1191+ Intent intent = Intent .parseUri (url , Intent .URI_INTENT_SCHEME );
1192+ if (intent != null ) {
1193+ PackageManager packageManager = context .getPackageManager ();
1194+ ResolveInfo info = packageManager .resolveActivity (intent , PackageManager .MATCH_DEFAULT_ONLY );
1195+ if (info != null ) {
1196+ context .startActivity (intent );
1197+ return true ;
1198+ } else {
1199+ String fallbackUrl = intent .getStringExtra ("browser_fallback_url" );
1200+ if (fallbackUrl != null && !fallbackUrl .isEmpty ()){
1201+ inAppWebView .loadUrl (fallbackUrl );
1202+ //Alternative: call external browser:
1203+ //Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(fallbackUrl));
1204+ //context.startActivity(browserIntent);
1205+ return true ;
1206+ }
1207+ }
1208+ }
1209+ } catch (Exception e ) {
1210+ LOG .e (LOG_TAG , "Error with " + url + ": " + e .toString ());
1211+ }
1212+
11701213 // If sms:5551212?body=This is the message
1171- else if (url .startsWith ("sms:" )) {
1214+ } else if (url .startsWith ("sms:" )) {
11721215 try {
11731216 Intent intent = new Intent (Intent .ACTION_VIEW );
11741217
0 commit comments