The code is pretty basic
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"));
}
});
The variable imageToSend is int – ID of the image in /drawables directory.
In the share dialog, I can see the Messaging as option. I choose it but no image is attached. There is a message “an image cannot be attached”. If I manually add image from the sdcard, then it’s being attached to the MMS message with no problems.
What may be the problem with the code above?
EDIT
Tried the other solution: attach image from 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 as well. I still get message that the file cannot be attached. And again Facebook app works flawlessly.
The intent is transfered to an external application.
The android:resource scheme is only valid locally.
That means that you have to copy the image from your resources to an external directory and link this new file in your Intent