Why does this code not attach an image to an MMS message?

The code is pretty simple

share_button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Uri image = Uri.parse("android.resource://com.mypac.app/" +
                        imageToSend);
                Intent share = new Intent(Intent.ACTION_SEND);
                share.setType("image/jpeg");
                share.putExtra(Intent.EXTRA_STREAM, image);

                startActivity(Intent.createChooser(share, "Share with"));
            }
        });

Variable imageToSend- this intis the directory identifier in the / drawables directory.

In the sharing dialog box, I see the "Messages As" option. I select it, but the image is not attached. The message "image cannot be attached" appears. If I manually add an image from the SD card, it will be attached to the MMS message without any problems.

What could be the problem with the above code?

EDIT

I tried another solution: attach the image from the SD. This is the code.

File file = new File(Environment.getExternalStorageDirectory(),
                        "img.png");
                share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
                startActivity(Intent.createChooser(share, "Share with"));

This does not work. I am still getting a message that the file could not be attached. And again, the Facebook app works flawlessly.

0
3

.

android: .

,

+4

Uri.parse()? ?

:

Resources resources = context.getResources(); 
Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + 
resources.getResourcePackageName(imageToSend) + '/' + 
resources.getResourceTypeName(imageToSend) + '/' + 
resources.getResourceEntryName(imageToSend) ); 
0

All Articles