summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaesu Lee <taesu82.lee@samsung.com>2020-02-03 19:02:50 +0900
committerLuca Stefani <luca.stefani.ge1@gmail.com>2020-03-16 16:29:45 +0100
commite853209938ee8144a5dd0dceb636f5c7438e8d29 (patch)
tree592be822121041ec19b7e6223e184aa304139512
parent48670efa8357c2a1dde3179b3e52397d063eea19 (diff)
downloadpackages_apps_Messaging-e853209938ee8144a5dd0dceb636f5c7438e8d29.tar.gz
packages_apps_Messaging-e853209938ee8144a5dd0dceb636f5c7438e8d29.tar.bz2
packages_apps_Messaging-e853209938ee8144a5dd0dceb636f5c7438e8d29.zip
Support sharing with image/video/audio/vcard and text fully
ACTION_SEND and ACTION_SEND_MULTIPLE support image, video, audio, text and vcard files. Test: Manual Change-Id: I1c08070f89877140aba9087717bb663ee2990467 Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
-rw-r--r--AndroidManifest.xml8
-rw-r--r--src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java126
2 files changed, 94 insertions, 40 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e3f65ae..75a60e1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -211,20 +211,16 @@
<intent-filter
android:label="@string/share_intent_label">
<action android:name="android.intent.action.SEND" />
+ <action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:mimeType="text/x-vCard" />
<data android:mimeType="text/x-vcard" />
<data android:mimeType="image/*" />
<data android:mimeType="audio/*" />
+ <data android:mimeType="video/*" />
<data android:mimeType="application/ogg" />
</intent-filter>
- <intent-filter
- android:label="@string/share_intent_label">
- <action android:name="android.intent.action.SEND_MULTIPLE" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="image/*" />
- </intent-filter>
</activity>
<!-- People & Options -->
diff --git a/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java b/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java
index 1c91e46..25d5ea3 100644
--- a/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java
+++ b/src/com/android/messaging/ui/conversationlist/ShareIntentActivity.java
@@ -24,6 +24,8 @@ import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
+import androidx.collection.ArrayMap;
+
import com.android.messaging.Factory;
import com.android.messaging.datamodel.data.ConversationListItemData;
import com.android.messaging.datamodel.data.MessageData;
@@ -37,8 +39,13 @@ import com.android.messaging.util.MediaMetadataRetrieverWrapper;
import com.android.messaging.util.FileUtil;
import com.android.messaging.util.UriUtil;
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Map;
public class ShareIntentActivity extends BaseBugleActivity implements
ShareIntentFragment.HostInterface {
@@ -89,51 +96,68 @@ public class ShareIntentActivity extends BaseBugleActivity implements
contentUri, intent.getType(), contentType));
}
if (ContentType.TEXT_PLAIN.equals(contentType)) {
- final String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
- if (sharedText != null) {
- mDraftMessage = MessageData.createSharedMessage(sharedText);
- } else {
- mDraftMessage = null;
+ String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
+ if (sharedText == null) {
+ // Try to get text string from content uri.
+ sharedText = getTextStringFromContentUri(contentUri);
}
- } else if (ContentType.isImageType(contentType) ||
- ContentType.isVCardType(contentType) ||
- ContentType.isAudioType(contentType) ||
- ContentType.isVideoType(contentType)) {
+ mDraftMessage =
+ sharedText != null ? MessageData.createSharedMessage(sharedText) : null;
+ } else if (ContentType.isMediaType(contentType)) {
if (contentUri != null) {
mDraftMessage = MessageData.createSharedMessage(null);
- addSharedImagePartToDraft(contentType, contentUri);
+ addSharedPartToDraft(contentType, contentUri);
} else {
mDraftMessage = null;
}
} else {
// Unsupported content type.
- Assert.fail("Unsupported shared content type for " + contentUri + ": " + contentType
- + " (" + intent.getType() + ")");
+ LogUtil.e(LogUtil.BUGLE_TAG, "Unsupported shared content type for " + contentUri
+ + ": " + contentType + " (" + intent.getType() + ")");
+ mDraftMessage = null;
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
final String contentType = intent.getType();
- if (ContentType.isImageType(contentType)) {
- // Handle sharing multiple images.
- final ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(
- Intent.EXTRA_STREAM);
- if (imageUris != null && imageUris.size() > 0) {
- mDraftMessage = MessageData.createSharedMessage(null);
- for (final Uri imageUri : imageUris) {
- if (UriUtil.isFileUri(imageUri)) {
- LogUtil.i(
- LogUtil.BUGLE_TAG,
+ // Handle sharing multiple contents.
+ final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
+ if (uris != null && !uris.isEmpty()) {
+ ArrayMap<Uri, String> uriMap = new ArrayMap<Uri, String>();
+ StringBuffer strBuffer = new StringBuffer();
+ for (final Uri uri : uris) {
+ if (UriUtil.isFileUri(uri)) {
+ LogUtil.i(LogUtil.BUGLE_TAG,
"Ignoring attachment from file URI which are no longer supported.");
- continue;
+ continue;
+ }
+ final String actualContentType = extractContentType(uri, contentType);
+ if (ContentType.TEXT_PLAIN.equals(actualContentType)) {
+ // Try to get text string from content uri.
+ String sharedText = getTextStringFromContentUri(uri);
+ if (sharedText != null) {
+ if (strBuffer.length() > 0) {
+ strBuffer.append("\n");
+ }
+ strBuffer.append(sharedText);
}
- final String actualContentType = extractContentType(imageUri, contentType);
- addSharedImagePartToDraft(actualContentType, imageUri);
+ } else if (ContentType.isMediaType(actualContentType)) {
+ uriMap.put(uri, actualContentType);
+ } else {
+ // Unsupported content type.
+ LogUtil.e(LogUtil.BUGLE_TAG, "Unsupported shared content type for " + uri
+ + ": " + actualContentType);
+ }
+ }
+
+ if (strBuffer.length() > 0 || !uriMap.isEmpty()) {
+ mDraftMessage = MessageData.createSharedMessage(strBuffer.toString());
+ for (final Map.Entry<Uri, String> e : uriMap.entrySet()) {
+ addSharedPartToDraft(e.getValue(), e.getKey());
}
- } else {
- mDraftMessage = null;
}
} else {
- // Unsupported content type.
- Assert.fail("Unsupported shared content type: " + contentType);
+ // No EXTRA_STREAM.
+ LogUtil.e(LogUtil.BUGLE_TAG, "No shared URI.");
+ mDraftMessage = null;
}
} else {
// Unsupported action.
@@ -141,6 +165,40 @@ public class ShareIntentActivity extends BaseBugleActivity implements
}
}
+ private static String getTextStringFromContentUri(final Uri contentUri) {
+ if (contentUri == null) {
+ return null;
+ }
+ final ContentResolver resolver = Factory.get().getApplicationContext().getContentResolver();
+ BufferedReader reader = null;
+ try {
+ final InputStream in = resolver.openInputStream(contentUri);
+ reader = new BufferedReader(new InputStreamReader(in));
+ String line = reader.readLine();
+ if (line == null) {
+ return null;
+ }
+ StringBuffer strBuffer = new StringBuffer(line);
+ while ((line = reader.readLine()) != null) {
+ strBuffer.append("\n").append(line);
+ }
+ return strBuffer.toString();
+ } catch (FileNotFoundException e) {
+ LogUtil.w(LogUtil.BUGLE_TAG, "Can not find contentUri " + contentUri);
+ } catch (IOException e) {
+ LogUtil.w(LogUtil.BUGLE_TAG, "Can not read contentUri", e);
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ return null;
+ }
+
private static String extractContentType(final Uri uri, final String contentType) {
if (uri == null) {
return contentType;
@@ -171,12 +229,12 @@ public class ShareIntentActivity extends BaseBugleActivity implements
return contentType;
}
- private void addSharedImagePartToDraft(final String contentType, final Uri imageUri) {
- if (FileUtil.isInPrivateDir(imageUri)) {
- Assert.fail("Cannot send private file " + imageUri.toString());
+ private void addSharedPartToDraft(final String contentType, final Uri uri) {
+ if (FileUtil.isInPrivateDir(uri)) {
+ Assert.fail("Cannot send private file " + uri.toString());
} else {
- mDraftMessage.addPart(PendingAttachmentData.createPendingAttachmentData(contentType,
- imageUri));
+ mDraftMessage.addPart(
+ PendingAttachmentData.createPendingAttachmentData(contentType, uri));
}
}