Attaching images to MMS

纵饮孤独 提交于 2019-12-06 15:07:41

问题


I am trying to attach an image that is picked from the image gallery to a MMS.

I am using the following code

public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == RESULT_OK) {
    if (requestCode == SELECT_PICTURE) {

        Uri selectedImageUri = data.getData();
        selectedImagePath = getPath(selectedImageUri);
        Uri uri = Uri.parse(selectedImagePath);
        Intent sendIntent = new Intent(Intent.ACTION_SEND); 
        sendIntent.putExtra("sms_body", "some text"); 
        sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
        sendIntent.setType("image/png"); 
        startActivity(Intent.createChooser(sendIntent, ""));
    }
}

When I select the image it is redirecting to the MMS application but displaying a toast which says Sorry you could not attach this image.

When I tried to email the same image there was no errors thrown. Here is the Logcat output.

01-27 16:04:26.485: ERROR/Mms/media(728): IOException caught while opening or reading stream
01-27 16:04:26.485: ERROR/Mms/media(728): java.io.FileNotFoundException: No content provider: /sdcard/6906-lightning.jpg
01-27 16:04:26.485: ERROR/Mms/media(728):     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:507)
01-27 16:04:26.485: ERROR/Mms/media(728):     at android.content.ContentResolver.openInputStream(ContentResolver.java:345)
01-27 16:04:26.485: ERROR/Mms/media(728):     at java.lang.reflect.Method.invoke(Method.java:521)

I want to also know how to insert a pre defined PhoneNumber when the MMS application is opened.


回答1:


Sorted it...

My Mistake. Instead of uri stream i passed the image location.

Solved it by using...

sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(selectedImageUri.toString()));


来源:https://stackoverflow.com/questions/4815389/attaching-images-to-mms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!