从Android分享到Google+

Ram*_*ain 1 android google-plus

Google+是否支持从Android应用分享?我想知道,因为我已经在我的应用程序上为twitter和facebook实现了这个,并希望对Google+做同样的事情.我确实读过他们现在有一个API,但它只用于开发和测试,并且无法发布应用程序.它是否正确?

Jam*_*ken 5

例如,在您的XML中:

<Button
  android:id="@+id/share_button"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Share on Google+" />
Run Code Online (Sandbox Code Playgroud)

在您的活动中:

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 = ShareCompat.IntentBuilder.from(ExampleActivity.this)
          .setType("text/plain")
          .setText("Welcome to the Google+ platform. https://developers.google.com/+")
          .getIntent()
          .setPackage("com.google.android.apps.plus");

      startActivity(shareIntent);
    }
});
Run Code Online (Sandbox Code Playgroud)