Pawan Kumar
Pawan Kumar

Reputation: 273

Attaching video to mms intent fails on specific devices

I had problems attaching a video file (it's always smaller than 100KB) via mms intent. Though this works perfectly well on karbonn A21 (ICS 4.0.4), the attachment fails on HTC one V (ICS 4.0.3) and lg-p920 (2.2.2). I get a toast like "unable to attach video to message"

This is the code I have

Uri uri = Uri.fromFile(videoFile);

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("video/3gp");
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body", "some text here");
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(sendIntent);

Any hints/clues/pointers on what I could do would be helpful.

Upvotes: 0

Views: 1065

Answers (2)

Nguyen Hieu
Nguyen Hieu

Reputation: 36

this problem cause because in the video/image need to add to galley:

Read code in

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/2.3.3_r1/com/android/mms/ui/ComposeMessageActivity.java

focus in addAttachment part, I saw

  String path = c.getString(c.getColumnIndexOrThrow(Images.Media.DATA));
    mSrc = path.substring(path.lastIndexOf('/') + 1);
    mContentType = c.getString(c.getColumnIndexOrThrow(
    mages.Media.MIME_TYPE));
    if (TextUtils.isEmpty(mContentType)) {
    throw new MmsException("Type of media is unknown.");
    })

We saw the message throwed not clear and cause misunderstand.

To solve this, you need to add the file to gallery, pass the URI get from contentResolver.insert to Intent with key Intent.EXTRA_STREAM

One more experience of my when using MMS, the default Activity class use to send MMS change among devices and manufatories, so the setClass com.android.mms.ui.ComposeMessageActivity not always right, it can cause ActivityNotFoundException. When it happends, you must call setPackge("com.android.mms") and remove setClass call. Hope it help

Upvotes: 2

Pawan Kumar
Pawan Kumar

Reputation: 273

My approach so far has been to let the user share the video via gmail, youtube and such along with an option to share via mms

ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.TITLE, "Cool Video");
content.put(Video.VideoColumns.DATE_ADDED,
            System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/3gp");
content.put(MediaStore.Video.Media.DATA, videoFile.getAbsolutePath());

ContentResolver resolver = parentActivity.get().getContentResolver();

//I use two URI's. One for the intent with mms(MMSUri) and the   
//other(ShareURi) is for sharing video with other social apps like
//gmail, youtube, facebook etc. 
Uri ShareUri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,content);
Uri MMSUri = Uri.fromFile(videoFile);

List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(sendIntent, 0);
if(!resInfo.isEmpty())
{
    for (ResolveInfo resolveInfo : resInfo) 
    {
        String packageName = resolveInfo.activityInfo.packageName;
        Intent targetIntent = new Intent(Intent.ACTION_SEND);
        targetIntent.setType("video/3gp");
        targetIntent.setPackage(packageName);

        if(packageName.contains("mms"))
        {
             targetIntent.putExtra("sms_body", "Some text here");
             targetIntent.putExtra(Intent.EXTRA_STREAM, MMSUri);
        }
        else
        {
            targetIntent.putExtra(Intent.EXTRA_SUBJECT, "I can has videos?");
            targetIntent.putExtra(Intent.EXTRA_TITLE, "Some title here");
            targetIntent.putExtra(Intent.EXTRA_TEXT,"You have gots to watch this");
            targetIntent.putExtra(Intent.EXTRA_STREAM, ShareUri);
        }
        targetedIntents.add(targetIntent);
    }           

    Intent chooserIntent = Intent.createChooser(targetedIntents.remove(0), "Select app to share");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedIntents.toArray(new Parcelable[]{}));

    startActivity(chooserIntent);
    return;
}

Toast.makeToast(this, "No intents found for this action", Toast.LENGTH_SHORT, Gravity.CENTER).show();

I try to populate my own target intents for the Intent.createChooser knowing only these would work in attaching/uploading my video

EDIT: I wont be accepting my own answer as the right one. I'm most optimistic there's a better one out there

Upvotes: 0

Related Questions