diff options
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-customurlscheme/src/android')
| -rw-r--r-- | StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java index 9d3f3d63..3a52d287 100644 --- a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java @@ -4,6 +4,8 @@ import android.content.Intent; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaActivity; import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaInterface; +import org.apache.cordova.CordovaWebView; import org.apache.cordova.PluginResult; import org.json.JSONArray; import org.json.JSONException; @@ -16,19 +18,52 @@ import java.util.Locale; public class LaunchMyApp extends CordovaPlugin { private static final String ACTION_CHECKINTENT = "checkIntent"; + private static final String ACTION_CLEARINTENT = "clearIntent"; + private static final String ACTION_GETLASTINTENT = "getLastIntent"; + + private String lastIntentString = null; + + /** + * We don't want to interfere with other plugins requiring the intent data, + * but in case of a multi-page app your app may receive the same intent data + * multiple times, that's why you'll get an option to reset it (null it). + * + * Add this to config.xml to enable that behaviour (default false): + * <preference name="CustomURLSchemePluginClearsAndroidIntent" value="true"/> + */ + private boolean resetIntent; + + @Override + public void initialize(final CordovaInterface cordova, CordovaWebView webView){ + this.resetIntent = preferences.getBoolean("resetIntent", false) || + preferences.getBoolean("CustomURLSchemePluginClearsAndroidIntent", false); + } @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - if (ACTION_CHECKINTENT.equalsIgnoreCase(action)) { + if (ACTION_CLEARINTENT.equalsIgnoreCase(action)) { + final Intent intent = ((CordovaActivity) this.webView.getContext()).getIntent(); + if (resetIntent){ + intent.setData(null); + } + return true; + } else if (ACTION_CHECKINTENT.equalsIgnoreCase(action)) { final Intent intent = ((CordovaActivity) this.webView.getContext()).getIntent(); final String intentString = intent.getDataString(); - if (intentString != null && intentString.contains("://") && intent.getScheme() != null) { + if (intentString != null && intent.getScheme() != null) { + lastIntentString = intentString; callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, intent.getDataString())); - intent.setData(null); } else { callbackContext.error("App was not started via the launchmyapp URL scheme. Ignoring this errorcallback is the best approach."); } return true; + } else if (ACTION_GETLASTINTENT.equalsIgnoreCase(action)) { + if(lastIntentString != null) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, lastIntentString)); + } else { + callbackContext.error("No intent received so far."); + } + return true; } else { callbackContext.error("This plugin only responds to the " + ACTION_CHECKINTENT + " action."); return false; @@ -38,8 +73,10 @@ public class LaunchMyApp extends CordovaPlugin { @Override public void onNewIntent(Intent intent) { final String intentString = intent.getDataString(); - if (intentString != null && intentString.contains("://") && intent.getScheme() != null) { - intent.setData(null); + if (intentString != null && intent.getScheme() != null) { + if (resetIntent){ + intent.setData(null); + } try { StringWriter writer = new StringWriter(intentString.length() * 2); escapeJavaStyleString(writer, intentString, true, false); @@ -133,4 +170,4 @@ public class LaunchMyApp extends CordovaPlugin { private static String hex(char ch) { return Integer.toHexString(ch).toUpperCase(Locale.ENGLISH); } -}
\ No newline at end of file +} |
