You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2021/03/30 12:43:34 UTC
[cordova-android] branch master updated: feat: handle intent://
scheme links with browser_fallback_url param (#1167)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
The following commit(s) were added to refs/heads/master by this push:
new d22af02 feat: handle intent:// scheme links with browser_fallback_url param (#1167)
d22af02 is described below
commit d22af021ee0dde0b28de4d019d0d44a022e4760b
Author: Alexander <xo...@gmail.com>
AuthorDate: Tue Mar 30 15:43:27 2021 +0300
feat: handle intent:// scheme links with browser_fallback_url param (#1167)
* fix showWebPage url intent:// now works
* android handle external url `intent://` scheme
* code refactoring
Co-authored-by: Андреянов Александр Николаевич <a....@sevstar.net>
Co-authored-by: Tim Brust <gi...@timbrust.de>
---
.../src/org/apache/cordova/CordovaWebViewImpl.java | 36 +++++++++++++++-------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
index 92579a8..b0ddcf4 100644
--- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
@@ -19,6 +19,7 @@
package org.apache.cordova;
import android.annotation.SuppressLint;
+import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
@@ -34,6 +35,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Constructor;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -232,25 +234,37 @@ public class CordovaWebViewImpl implements CordovaWebView {
LOG.w(TAG, "showWebPage: Refusing to send intent for URL since it is not in the <allow-intent> whitelist. URL=" + url);
return;
}
+
+ Intent intent = null;
try {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- // To send an intent without CATEGORY_BROWSER, a custom plugin should be used.
- intent.addCategory(Intent.CATEGORY_BROWSABLE);
- Uri uri = Uri.parse(url);
- // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
- // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
- if ("file".equals(uri.getScheme())) {
- intent.setDataAndType(uri, resourceApi.getMimeType(uri));
+ if (url.startsWith("intent://")) {
+ intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} else {
- intent.setData(uri);
+ intent = new Intent(Intent.ACTION_VIEW);
+ // To send an intent without CATEGORY_BROWSER, a custom plugin should be used.
+ intent.addCategory(Intent.CATEGORY_BROWSABLE);
+ Uri uri = Uri.parse(url);
+ // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
+ // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
+ if ("file".equals(uri.getScheme())) {
+ intent.setDataAndType(uri, resourceApi.getMimeType(uri));
+ } else {
+ intent.setData(uri);
+ }
}
if (cordova.getActivity() != null) {
cordova.getActivity().startActivity(intent);
} else {
LOG.d(TAG, "Cordova activity does not exist.");
}
- } catch (android.content.ActivityNotFoundException e) {
- LOG.e(TAG, "Error loading url " + url, e);
+ } catch (URISyntaxException e) {
+ LOG.e(TAG, "Error parsing url " + url, e);
+ } catch (ActivityNotFoundException e) {
+ if (url.startsWith("intent://") && intent != null && intent.getStringExtra("browser_fallback_url") != null) {
+ showWebPage(intent.getStringExtra("browser_fallback_url"), openExternal, clearHistory, params);
+ } else {
+ LOG.e(TAG, "Error loading url " + url, e);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org