How to share an image of imageswitcher of my app on Facebook?

I'm making an app for Android. I have a gallery of photos, and I'd want to offer the possibility to share the imageswitcher on Facebook clicking a button (only the photo that is being shown in that moment). How can I do this?

Thanks!

Answers


If you are familiar with the Facebook SDK for Android, try this:

//Getting the image
    Bitmap bm = theImageViewToUpload.getDrawingCache();
    byte[] bArray = null;
    ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 100, baoStream);
    bArray = baoStream.toByteArray();

    Bundle bund = new Bundle();
    bund.putString(Facebook.TOKEN, access_token);
    bundle.putString("caption", "This is your image-caption on Facebook");
    bund.putByteArray("picture", bArray);

    //Uploading to Facebook
    try {
        fb.request("me/photos", bund, "POST");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

If you are not familiar with the Facebook SDK, I'm not planning on teaching you everything in an answer here, but take a look at their reference: http://developers.facebook.com/docs/reference/androidsdk/

Edit: Add this code to your onClick of the button you are planning to use.


Need Your Help

Creating a random epoch value ranging from X days ago and now

java random epoch

Trying to create an epoch value, in Java, where returned value is between now and 14 days ago.