Good call...

Both
Uri uri = Uri.parse("android.resource://com.package.android.test/
drawable/icon");
and...
Uri uri = Uri.parse("android.resource://com.package.android.test/raw/
icon");

...work fine with Gmail.

But both throw an exception when I choose 'Messaging':

 Caused by: java.lang.NullPointerException
   at com.android.mms.ui.UriImage.<init>(UriImage.java:68)
   at
com.android.mms.model.ImageModel.initModelFromUri(ImageModel.java:78)
   at com.android.mms.model.ImageModel.<init>(ImageModel.java:60)
   at
com.android.mms.data.WorkingMessage.changeMedia(WorkingMessage.java:
427)
   at
com.android.mms.data.WorkingMessage.setAttachment(WorkingMessage.java:
343)

On Jun 14, 2:35 pm, Sean Hodges <[email protected]> wrote:
> > This acutally works if I select gmail, although the image name gets
> > changed to the resource id. However if I choose 'Messaging' from the
> > intent chooser, it throws a null pointer.
>
> That's very odd. Have you tried the "package/type/name" format instead
> of "package/id"?
>
> Uri uri = 
> Uri.parse("android.resource://com.package.android.test/drawable/icon");
>
> Or, alternatively, there might be something fishy with drawables
> specifically, copy the image into the raw/ assets and try:
>
> Uri uri = Uri.parse("android.resource://com.package.android.test/raw/icon");
>
> I'll give it a test tonight. As I said, the MMS ("Messaging") app
> requires the image to be read in by BitmapFactory. It might be having
> trouble with the fact the location is read-only... My guess is that
> the Email/GMail apps reference the image file directly, and don't try
> to transform it before sending.
>
> On Mon, Jun 14, 2010 at 12:14 PM, Neilz <[email protected]> wrote:
> > This whole functionality seems really inconsistent - I now remember
> > that I've tried this before and given up.
>
> > I tried this code:
>
> > Intent i=new Intent(android.content.Intent.ACTION_SEND);
> > i.setType("image/jpg");
> > i.putExtra(Intent.EXTRA_SUBJECT, "Neils Subject");
> > i.putExtra(Intent.EXTRA_TEXT, "Hello Neil, check this out");
> > i.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://sdcard/DCIM/Camera/
> > 2010-05-02 13.19.32.jpg"));
> > startActivity(i);
>
> > This sends an email but there's no attachment (it exists!)
>
> > I also tried this code:
>
> > Uri uri = Uri.parse("android.resource://com.package.android.test/" +
> > R.drawable.icon);
> > Intent i=new Intent(android.content.Intent.ACTION_SEND);
> > i.setType("image/jpg");
> > i.putExtra(Intent.EXTRA_SUBJECT, "Neils Subject");
> > i.putExtra(Intent.EXTRA_TEXT, "Hello Neil, check this out");
> > i.putExtra(Intent.EXTRA_STREAM, uri);
> > startActivity(i);
>
> > This acutally works if I select gmail, although the image name gets
> > changed to the resource id. However if I choose 'Messaging' from the
> > intent chooser, it throws a null pointer.
>
> > On Jun 14, 11:55 am, Sean Hodges <[email protected]> wrote:
> >> I'm not sure of the best way to do this; but my understanding of the
> >> mechanism is that the image is pulled from any given content provider
> >> URI, just so long as the data returned can be understood by
> >> BitmapFactory.decodeStream().
>
> >> So a simple solution would be to create a new ContentProvider and pass
> >> a corresponding URI to the Intent (instead of
> >> "content://content/external/images/..."). You could then send a
> >> drawable from your app using this custom content provider in the form
> >> of a ByteArrayOutputStream.
>
> >> A second approach would be to copy the drawable image to the external
> >> storage, and use the URI format I gave in the example.
>
> >> On Mon, Jun 14, 2010 at 10:57 AM, Neilz <[email protected]> wrote:
> >> > I've just been looking for something like this myself... a timely
> >> > topic.
>
> >> > Please could you edit this code to show how I would send an image from
> >> > the @drawable folder?
>
> >> > On Jun 9, 4:29 pm, Sean Hodges <[email protected]> wrote:
> >> >> Mike,
>
> >> >> I can do a little more than that, I can give you a fully working unit
> >> >> test with the phone number pre-populated in the From: field:
>
> >> >> package com.seanhodges.sandbox;
>
> >> >> import android.content.Intent;
> >> >> import android.net.Uri;
> >> >> import android.test.AndroidTestCase;
>
> >> >> public class SendAnMMS extends AndroidTestCase {
>
> >> >>         public void testSendingAnMMS() throws Exception {
> >> >>                 Intent intent = new Intent(Intent.ACTION_SEND);
> >> >>                 intent.putExtra("address", "12345");
> >> >>                 intent.putExtra("sms_body", "See attached picture");
>
> >> >>                 intent.putExtra(Intent.EXTRA_STREAM,
> >> >> Uri.parse("content://media/external/images/thumbnails/0"));
> >> >>                 intent.setType("image/png");
>
> >> >>                 // This is added just so the AndroidTestCase launches 
> >> >> the activity
> >> >> as expected, remove this line in your production code
> >> >>                 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
>
> >> >>                 getContext().startActivity(intent);
> >> >>         }
>
> >> >> }
>
> >> >> If the referenced image does not exist, you should get a warning
> >> >> pop-up when the SMS app launches.
>
> >> >> On Wed, Jun 9, 2010 at 3:57 PM, mike <[email protected]> wrote:
> >> >> > Hi Sean,
>
> >> >> > didn't get it at all. can you give me an example??
>
> >> >> > regards,
> >> >> > Mike
>
> >> >> > --
> >> >> > You received this message because you are subscribed to the Google
> >> >> > Groups "Android Developers" group.
> >> >> > To post to this group, send email to 
> >> >> > [email protected]
> >> >> > To unsubscribe from this group, send email to
> >> >> > [email protected]
> >> >> > For more options, visit this group at
> >> >> >http://groups.google.com/group/android-developers?hl=en
>
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "Android Developers" group.
> >> > To post to this group, send email to [email protected]
> >> > To unsubscribe from this group, send email to
> >> > [email protected]
> >> > For more options, visit this group at
> >> >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to