0

I am sharing a single photo to the facebook,twitter,Linkedin,picasa. I can share text without any problem.Can any one explain with some example how to share a single photo.For the moment I am using the following code (Adding an Easy Share Action)

private ShareActionProvider mShareActionProvider;

  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate menu resource file.
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem item = menu.findItem(R.id.menu_item_share);
    mShareActionProvider = (ShareActionProvider) item.getActionProvider();
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    //Uri screenshotUri = Uri.fromFile(new File(getFilesDir(), ".jpg"));
    Log.d("Storage dir ", "Getting the directory");
    File f = FileUtils.getStorageDir();
    Log.d("All Answers: ", f.getAbsolutePath());
    sharingIntent.setType("image/png");
    sharingIntent.putExtra(Intent.EXTRA_STREAM,f);      
    startActivity(Intent.createChooser(sharingIntent, "Share image using"));
    // Set the share Intent
    mShareActionProvider.setShareIntent(sharingIntent);
    return true;
  }

  // Call to update the share intent
  private void setShareIntent(Intent shareIntent) {
    if (mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(shareIntent);
    }
  }
}

Thanks in Advance

Simulant
  • 19,190
  • 8
  • 63
  • 98
  • I answered about question like this: http://stackoverflow.com/questions/19700889/share-link-via-intent-from-preferencescreen/19704522#19704522 – user2940520 Nov 21 '13 at 11:10

3 Answers3

1

Sharing binary objects (Images, videos etc.) You can use this code

In addition to supporting text, this intent also supports sharing images or any binary content. All you have to do is to set the appropriate mime type and then pass the binary data by calling the put Extra method.

 Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);

sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));

Registering for the Intent

If you want your app to be listed when this Intent is called, then you have to add an intent filter in your manifest.xml file

<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="image/*" />
</intent-filter>

you will open Chooser dialog and select facebook and shared photo on facebook,twitter,Linkedin etc.

Sunil
  • 53
  • 7
0

Try this code :

    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)));

It will open chooser dialog with all possible applications allowing photo sharing facility.Just select Facebook ,Twitter or any other application on which you want to share your photo.

Zankhna
  • 4,570
  • 9
  • 62
  • 103
0

SocialLib is an excellent share kit for android (for iOS best is ShareKit).

SocialLib allows to integrate : Facebook Twitter Google Buzz LinkedIn

And if you want to use only facebook to share follow Facebook Share Dialog.

Siddiq Abu Bakkar
  • 1,949
  • 1
  • 13
  • 24