0

我在通过 mms 意图附加视频文件(总是小于 100KB)时遇到问题。虽然这在 karbonn A21 (ICS 4.0.4) 上运行良好,但附件在 HTC one V (ICS 4.0.3) 和 lg-p920 (2.2.2) 上失败。我得到了“无法将视频附加到消息”之类的祝酒词

这是我的代码

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);

关于我能做什么的任何提示/线索/指针都会有所帮助。

4

2 回答 2

2

这个问题是因为在视频/图像中需要添加到厨房:

读入代码

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

关注 addAttachment 部分,我看到了

  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.");
    })

我们看到消息抛出不清楚并引起误解。

要解决这个问题,您需要将文件添加到画廊,将 URI 从 contentResolver.insert 获取到 Intent,并使用键 Intent.EXTRA_STREAM

我在使用彩信时的另一个经验,默认的Activity类用于在设备和制造商之间发送彩信更改,因此setClass com.android.mms.ui.ComposeMessageActivity 并不总是正确的,它可能会导致ActivityNotFoundException。当它发生时,您必须调用 setPackge("com.android.mms") 并删除 setClass 调用。希望有帮助

于 2013-09-19T04:01:40.187 回答
0

到目前为止,我的方法是让用户通过 gmail、youtube 等分享视频,以及通过 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();

我尝试填充我自己的目标意图,Intent.createChooser因为只知道这些意图在附加/上传我的视频时起作用

编辑:我不会接受我自己的答案是正确的。我最乐观的是那里有更好的

于 2013-02-11T06:44:44.347 回答