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.
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