Search code examples
androidmmsandroid-image

Getting URI for image in drawable to be sent in MMS


this is my first post here so I am really sorry if I break some rules. Please correct me where I go wrong.

Now to the question, I have searched back and forth on stackoverflow and other websites/internet but I can't seem to find the right answer.

I am trying to attach a jpg frm the drawable folder to my MMS. I am using this code for sending MMS.

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/jpg");
intent.putExtra(Intent.EXTRA_STREAM,path);
startActivity(intent);

The intent works fine for me and the mms application loads IF i don't add the URI path to it. However, when I add the path, the app crashes. I've tried numerous ways of adding the image from the drawable that i found here at stackoverflow or other websites.

I am writing some of them here, all of them didn't work for me.

Uri path = Uri.parse("android.resource://com.android.MYAPP/drawable/imagename");

And

String uri = "drawable/icon";
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
Uri path = Uri.parse("android.resource://com.android.MMSAPP/drawable/" + imageResource);

And

Uri path = Uri.parse("android.resource://com.android.MMSAPP/" + R.drawable.imageName);

I have stuck with this problem from the last several days and I would be really thankful if I can find the right answer.

Thank you so much in advance.


Solution

  • I am still not sure why I was getting error with code that was working fine for everyone else, however, I used the assetmanager and things worked for me.