Skip to content

Commit

Permalink
added support for Andoird 8/9 for sharing text/html
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Heizmann committed Mar 30, 2019
1 parent ce53001 commit 331e244
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/android/cc/fovea/openwith/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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);
}
Expand Down Expand Up @@ -153,6 +161,27 @@ 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.
*/
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("text", text);
return json;
}

/** Return data contained at a given Uri as Base64. Defaults to null. */
public static String getDataFromURI(
final ContentResolver contentResolver,
Expand Down

0 comments on commit 331e244

Please sign in to comment.