Search code examples
androidvideomms

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.


Solution

  • 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