How to share image in google Plus through an android app?

Deepika Lalra picture Deepika Lalra · Oct 15, 2012 · Viewed 9.9k times · Source

I have already tried this code, but i didn't saw photo shared in my account.

File file = new File("sdcard/1346249742258.jpg");
String photoUri = null;
photoUri = file.getAbsolutePath();

Intent shareIntent = ShareCompat.IntentBuilder.from(this)
        .setText("Sharing an image on Google!").setType("image/jpeg")
        .setStream(Uri.parse(photoUri)).getIntent()
        .setPackage("com.google.android.apps.plus");
startActivity(shareIntent);

Answer

Chirag Shah picture Chirag Shah · Oct 17, 2012

The Google+ app only supports content:// URIs. You will need to use the MediaStore API for this purpose.

 File tmpFile = new File("/path/to/image");
 final String photoUri = MediaStore.Images.Media.insertImage(
         getContentResolver(), tmpFile.getAbsolutePath(), null, null);

 Intent shareIntent = ShareCompat.IntentBuilder.from(this)
         .setText("Hello from Google+!")
         .setType("image/jpeg")
         .setStream(Uri.parse(photoUri))
         .getIntent()
         .setPackage("com.google.android.apps.plus");