Sharing prefilled posts to Google+ from your Android app

You can suggest text and recipients for posts on behalf of your users. The user can customize these values before they share to Google+.

Prefill the post text

You can suggest text for the user to share by prefilling the post text to help the user create a quality post that will drive engagement. For example, you might include a hashtag in your prefilled text that can help other users find the post.

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("Just tried this new restaurant! #nomnomnom #myappname")
      .setContentUrl(Uri.parse("https://developers.google.com/+/web/snippet/examples/restaurant"))
      .getIntent();

    startActivityForResult(shareIntent, 0);
  }
});

Mentioning people in the post text

You can mention specific people in the prefilled text by adding a plus sign (+) followed by their Google+ user ID or their email address, for example:

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("Heard about this restaurant from +109813896768294978296. Check out the menu +friendnotonplus@example.com")
      .setContentUrl(Uri.parse("https://developers.google.com/+/web/snippet/examples/restaurant"))
      .getIntent();

    startActivityForResult(shareIntent, 0);
  }
});

When the post is made, the user ID is changed to the user's name when displayed in the stream. For mentions that use an email address, an email notification is sent and in the stream the email address is replaced with +***** to protect the user's address.

Prefill the recipients of a post

When you share to Google+, your users will have the option to choose who should receive this post from a list of their Google contacts and Google+ circles. This list is presented to them along with suggestions of the people they interact with most. In addition, users can choose to share with their device contacts by searching for them. To use this feature, simply make sure you are using the latest SDK and the feature will be automatically enabled.

You can also manage these suggestions on your own by constructing a list of suggested recipients. When you use Google+ Sign-In, you can prefill up to 10 individuals to suggest to the user who to share the post with. The prefilled recipients is an array of Google+ user IDs or email addresses.

Your app, if it uses Google+ Sign-In, can load the user's list of friends that the user chose to make visible to your app. You might use this list of people to suggest recipients for the shared post.

The following example demonstrates how to prefill multiple recipients by passing an array of Google+ user IDs to the setRecipients method:

private ArrayList<Person> recipients;
// Load possible recipients loadVisiblePeople or manually create a list:
recipients.add(PlusShare.createPerson("106189723444098348646","Larry Page"));
recipients.add(PlusShare.createPerson("109813896768294978296","Sergey Brin"));

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("Just tried this new restaurant! #nomnomnom #myappname")
      .setRecipients(recipients)
      .setContentUrl(Uri.parse("https://developers.google.com/+/web/snippet/examples/restaurant"))
      .getIntent();

    startActivityForResult(shareIntent, 0);
  }
});

Next steps

Send feedback about...

Google+ Platform for Android
Google+ Platform for Android