views:

49

answers:

3

I trying to create a "publish" button for an image in my android app, that works with the Facebook App and Email.

This is my code (imagePath is something like "/sdcard/myapp/image.jpg"

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+imagePath));

sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");
startActivity(Intent.createChooser(sendIntent, "Email:"));

This works perfectly for sending the email with the attachment, but it doesn't work with the Facebook App. If I'm using

    sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imagePath));

the publishing for Facebook works - but the email-attachment isn't send anymore.

Any ideas what could do it for both?

A: 

You might have to define a ContentProvider which converts your file:// Uri to a content:// Uri.

You can try this one : http://code.google.com/p/openintents/source/browse/trunk/FileManager/src/org/openintents/filemanager/FileManagerProvider.java

Kevin Gaudin
Thank you for this approach - this could work, too. But I solved it in an easier way for me.
mseo
A: 

If anyone is interested ... I solved it in an indirect way:

    File imageFile = new File(imagePath);
    String url = "";
    try {
         url = Media.insertImage(getContentResolver(), imageFile.getAbsolutePath(), imageFile.getName(), imageFile.getName());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
mseo