diff --git a/plugin.xml b/plugin.xml index 8f6a4eb..2350f76 100644 --- a/plugin.xml +++ b/plugin.xml @@ -86,7 +86,7 @@ SOFTWARE. - + @@ -100,8 +100,8 @@ SOFTWARE. $ANDROID_MIME_TYPES $ANDROID_EXTRA_ACTIONS - - + + diff --git a/src/android/cc/fovea/openwith/Serializer.java b/src/android/cc/fovea/openwith/Serializer.java index 0bc6369..b1f2bfd 100644 --- a/src/android/cc/fovea/openwith/Serializer.java +++ b/src/android/cc/fovea/openwith/Serializer.java @@ -72,7 +72,10 @@ public static boolean readExitOnSent(final Bundle extras) { /** Extract the list of items from clip data (if available). * - * Defaults to null. */ + * Defaults to null. + * + * Expanded extraction list based on https://github.com/JochenHeizmann/cordova-plugin-openwith/commit/331e244a048c8aead1f58cc2e7e836893b0ddc55 + * */ public static JSONArray itemsFromClipData( final ContentResolver contentResolver, final ClipData clipData) @@ -81,7 +84,15 @@ public static JSONArray itemsFromClipData( final int clipItemCount = clipData.getItemCount(); JSONObject[] items = new JSONObject[clipItemCount]; for (int i = 0; i < clipItemCount; i++) { - items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).getUri()); + if (clipData.getItemAt(i).getUri() != null) { + items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).getUri()); + } else if (clipData.getItemAt(i).getText() != null) { + items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).getText().toString()); + } else if (clipData.getItemAt(i).getHtmlText() != null) { + items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).getHtmlText()); + } else { + items[i] = toJSONObject(contentResolver, clipData.getItemAt(i).toString()); + } } return new JSONArray(items); } @@ -153,6 +164,29 @@ public static JSONObject toJSONObject( return json; } + /** Convert an String to JSON object. + * + * Object will include: + * "type" of data; + * "text" itself; + * "path" to the file, if applicable. + * "data" for the file. + * + * Based on https://github.com/JochenHeizmann/cordova-plugin-openwith/commit/331e244a048c8aead1f58cc2e7e836893b0ddc55 + */ + public static JSONObject toJSONObject( + final ContentResolver contentResolver, + final String text) + throws JSONException { + if (text == null) { + return null; + } + final JSONObject json = new JSONObject(); + json.put("type", "text/plain"); + json.put("content", text); + return json; + } + /** Return data contained at a given Uri as Base64. Defaults to null. */ public static String getDataFromURI( final ContentResolver contentResolver, @@ -189,4 +223,4 @@ public static String getRealPathFromURI( return result; } } -// vim: ts=4:sw=4:et +// vim: ts=4:sw=4:et \ No newline at end of file