我在通过mms intent附加视频文件(它总是小于100KB)时遇到了问题。虽然这在karbonn A21(ICS 4.0.4)上运行良好,但在HTC one V(ICS 4.0.3)和lg-p920(2.2.2)上附着失败。我得到一个像#34;无法将视频附加到消息"
的祝酒词这是我的代码
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);
关于我能做什么的任何提示/线索/指示都会有所帮助。
答案 0 :(得分:2)
这个问题导致因为在视频/图像中需要添加到厨房:
阅读
中的代码关注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
我使用MMS时的另一种体验,默认的Activity类用于在设备和制造商之间发送MMS更改,因此setClass com.android.mms.ui.ComposeMessageActivity并不总是正确的,它可能导致ActivityNotFoundException。当它发生时,你必须调用setPackge(“com.android.mms”)并删除setClass调用。 希望有所帮助
答案 1 :(得分: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
填充我自己的目标意图,只知道这些可用于附加/上传我的视频
编辑:我不会接受我自己的答案作为正确答案。我最乐观的是那里有一个更好的那个