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.