Found one of the answers I needed on another old topic: An extra slash
is needed:
i.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///sdcard/DCIM/Camera/
picture.jpg"));
This solves the problem of sending via gmail.
I still can't work out how to send a drawable from the resources.
On Jun 14, 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