Legacy Google+ APIs have been shut down as of March 7, 2019. Changes to the shutdown plan have been made recently which may mitigate its effect on some developers. Learn more.

Google+ integrations for web and mobile apps have also stopped functioning as of March 7, 2019. Learn more.

Sharing to Google+ from your Android app

The Share dialog provides a means for users to share rich content from your app into the Google+ stream, including text, photos, URL attachments and location. In addition, your app can use two advanced sharing options: interactive posts and deep linking.

Additional examples demonstrate how to share interactive posts, upload media with posts, use deep linking, and prefill the share dialog.

Before you begin

You must create a Google API Console project and initialize the GoogleApiClient object.

Adding basic sharing

Basic sharing demonstrates the minimum code that is required to add sharing to Google+ from your app. You set up sharing by using the PlusShare.Builder methods, which you later build on to add advanced sharing features.

To add sharing:

  1. Add a share button to your layout.

    <Button
      android:id="@+id/share_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Share on Google+"
    />
    
  2. In your activity, configure your button's OnClickListener to share when clicked.

    Button shareButton = (Button) findViewById(R.id.share_button);
    shareButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
          // Launch the Google+ share dialog with attribution to your app.
          Intent shareIntent = new PlusShare.Builder(this)
              .setType("text/plain")
              .setText("Welcome to the Google+ platform.")
              .setContentUrl(Uri.parse("https://developers.google.com/+/"))
              .getIntent();
    
          startActivityForResult(shareIntent, 0);
        }
    });
    

Next, you can build on this code to add advanced features such as deep linking or interactive posts.

Additional sharing options

You might also want to explore the following approaches to sharing content from your app:

Next steps

发送以下问题的反馈:

此网页
Google+ Platform for Android
Google+ Platform for Android