Sharing images and videos to Google+ from your Android app

The PlusShare.Builder class provides a setStream method that you can use to attach an image or video to a shared post.

Share an image or video

The following example demonstrates using a picker intent to choose an image or video from the gallery to share on Google+ when the user clicks a button in your app.

In your activity, configure your button's OnClickListener to launch the picker intent when clicked.:

private static final int REQ_SELECT_PHOTO = 1;
private static final int REQ_START_SHARE = 2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ...

    Button shareMediaButton = (Button) findViewById(R.id.share_media);
    shareMediaButton.setOnClickListener(new android.view.View.OnClickListener() {
      public void onClick(View v) {
        Intent photoPicker = new Intent(Intent.ACTION_PICK);
        photoPicker.setType("video/*, image/*");
        startActivityForResult(photoPicker, REQ_SELECT_PHOTO);
      }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  super.onActivityResult(requestCode, resultCode, intent);

  if(requestCode == REQ_SELECT_PHOTO) {
    if(resultCode == RESULT_OK) {
      Uri selectedImage = intent.getData();
      ContentResolver cr = this.getContentResolver();
      String mime = cr.getType(selectedImage);

      PlusShare.Builder share = new PlusShare.Builder(this);
      share.setText("hello everyone!");
      share.addStream(selectedImage);
      share.setType(mime);
      startActivityForResult(share.getIntent(), REQ_START_SHARE);
    }
  }
}

When you share media to Google+, you cannot also use the setContentUrl method. If you want to include a URL in the post with the media, you should append the URL to the prefilled text in the setText() method.

Next steps

Send feedback about...

Google+ Platform for Android
Google+ Platform for Android