以简单的意图分享到 Google+(没有 PlusShare / Play 服务)

Sharing to Google+ with plain intents (without PlusShare / Play Services)

有没有一种简单的方法可以将 URL 和预填充文本共享到 Google+, 而无需 添加 Google Play Services 依赖项,仅使用普通 Android 意图?

我正在寻找与此类似的东西 solution for Twitter and this one for Facebook

我问是因为:

好吧,事实证明使用 Intent.ACTION_SEND 很容易,将整个共享文本(包括 URL)放入 Intent.EXTRA_TEXT:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, 
    "Just testing, check this out: ");
filterByPackageName(context, intent, "com.google.android.apps.plus");
context.startActivity(intent);

... 其中 filterByPackageName() 是这样的实用程序 (which I've posted before):

public static void filterByPackageName(Context context, Intent intent, String prefix) {
    List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 0);
    for (ResolveInfo info : matches) {
        if (info.activityInfo.packageName.toLowerCase().startsWith(prefix)) {
            intent.setPackage(info.activityInfo.packageName);
            return;
        }
    }
}

如果您是从您曾经使用 Google PlusShare.Builder API 的 Activity 执行此操作,您仍然可以调用 activity.startActivityForResult 并处理onActivityResult 和你之前做的完全一样。

与使用 PlusShare.Builder 相比,使用此手动构造的 Intent 调用 Plus 应用程序的一个缺点是用户必须选择 Google Plus 帐户(如果他有多个) 他想与之分享,无论您是否已经使用 Google.

将他登录到您的应用程序