From 0e4d0250b6bd798244c7b3ad00574ec9cf0d3a75 Mon Sep 17 00:00:00 2001 From: Daniel Gruber Date: Mon, 23 Feb 2015 03:36:57 +0100 Subject: [PATCH] Fix for Parcable Extra with Array and Uri --- src/android/WebIntent.java | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/android/WebIntent.java b/src/android/WebIntent.java index 180111d..433e93c 100644 --- a/src/android/WebIntent.java +++ b/src/android/WebIntent.java @@ -2,6 +2,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.ArrayList; import org.apache.cordova.CordovaActivity; import org.json.JSONArray; @@ -12,6 +13,7 @@ import android.content.Intent; import android.net.Uri; import android.text.Html; +import android.util.Log; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.PluginResult; @@ -29,6 +31,7 @@ public class WebIntent extends CordovaPlugin { private CallbackContext onNewIntentCallback = null; + private Intent newestIntent; /** * Executes the request and returns PluginResult. @@ -89,7 +92,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo callbackContext.sendPluginResult(res); return false; } - Intent i = ((CordovaActivity) this.cordova.getActivity()).getIntent(); + Intent i = getIntent(); String extraName = args.getString(0); PluginResult res = new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName)); callbackContext.sendPluginResult(res); @@ -101,15 +104,39 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo callbackContext.sendPluginResult(res); return false; } - Intent i = ((CordovaActivity) this.cordova.getActivity()).getIntent(); + Intent i = getIntent(); String extraName = args.getString(0); if (i.hasExtra(extraName)) { - PluginResult res = new PluginResult(PluginResult.Status.OK, i.hasExtra(extraName)); - callbackContext.sendPluginResult(res); - return true; + String r = i.getStringExtra(extraName); + if (null == r) { + Uri uri = ((Uri) i.getParcelableExtra(extraName)); + + if(uri != null) { + r = uri.toString(); + } + + Log.d("CORDOVA", "GetExtra"); + + if(null == r) { + ArrayList list = i.getParcelableArrayListExtra(extraName); + + JSONArray arr = new JSONArray(); + for(Uri u : list) { + arr.put(u.toString()); + } + + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, arr)); + return true; + } + } + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, r)); + return true; } else { + + Log.d("CORDOVA", "Does not have extra."); + PluginResult res = new PluginResult(PluginResult.Status.ERROR); callbackContext.sendPluginResult(res); return false; @@ -122,7 +149,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo return false; } - Intent i = ((CordovaActivity) this.cordova.getActivity()).getIntent(); + Intent i = getIntent(); String uri = i.getDataString(); callbackContext.success(uri); @@ -183,11 +210,20 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo @Override public void onNewIntent(Intent intent) { + this.newestIntent = intent; if (this.onNewIntentCallback != null) { this.onNewIntentCallback.success(intent.getDataString()); } } + Intent getIntent() { + if(this.newestIntent != null) { + return this.newestIntent; + } + + return ((CordovaActivity) this.cordova.getActivity()).getIntent(); + } + void startActivity(String action, Uri uri, String type, Map extras, Map handlerMap) { Intent i = (uri != null ? new Intent(action, uri) : new Intent(action)); @@ -232,4 +268,4 @@ void sendBroadcast(String action, Map extras) { ((CordovaActivity) this.cordova.getActivity()).sendBroadcast(intent); } -} \ No newline at end of file +}