仅分享到没有照片的Google +

时间:2015-05-14 19:58:25

标签: android android-intent

我举了很多例子,我可以像这样安装Android应用程序共享图像:

shareIntent = ShareCompat.IntentBuilder
                            .from(getActivity())
                            .setType("image/*")
                            .setStream(imageUris.get(0))
                            .getIntent()             
                            .setPackage("com.google.android.apps.plus");
                    startActivity(shareIntent);

但是现在当我这样做时,我会看到使用选择的完整动作:LINK

这对我的应用来说是不可接受的。我想只在goole plus中分享。没有google.photos真的是真的吗? 作为解决方案,我找到了这段代码:

Intent shareIntent = new Intent();
    shareIntent
            .setAction(imageUris.size() > 1 ? Intent.ACTION_SEND_MULTIPLE
                    : Intent.ACTION_SEND);
    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
    shareIntent.setType("image/*");
    PackageManager pm = context.getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setAction(imageUris.size() > 1 ? Intent.ACTION_SEND_MULTIPLE
            : Intent.ACTION_SEND);
    sendIntent.setType("image/*");
    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {

        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;

        if (packageName.equals("com.facebook.katana")) {
            shareIntent.setPackage(packageName);
            Log.e("NEW", "count   0");
        } else if (packageName.equals("com.google.android.apps.plus")

                || (packageName
                        .equals("com.yahoo.mobile.client.android.flickr") || packageName
                        .equals("com.twitter.android"))) {

            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName,
                    ri.activityInfo.name));
            intent.setAction(imageUris.size() > 1 ? Intent.ACTION_SEND_MULTIPLE
                    : Intent.ACTION_SEND);
            intent.setType("image/*");
            if (packageName.equals("com.google.android.apps.plus")) {
                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
                        imageUris);
            } else if (packageName
                    .equals("com.yahoo.mobile.client.android.flickr")) {
                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
                        imageUris);
            } else if (packageName.equals("com.twitter.android")) {
                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
                        imageUris);
            }

            intentList.add(new LabeledIntent(intent, packageName, ri
                    .loadLabel(pm), ri.icon)); 
        }

    }
    // removing google photos like in ios 
    for (int i = 0; i < intentList.size(); i++) {
        String a = intentList.get(i).getComponent().getClassName();
        if (a.contains("com.google.android.apps.photos")) {
            intentList.remove(i);
        }
    }
    // convert intentList to array
    LabeledIntent[] extraIntents = intentList
            .toArray(new LabeledIntent[intentList.size()]); 

    Intent openInChooser = Intent.createChooser(shareIntent, String.format(
            context.getString(R.string.format_share_photos),
            imageUris.size()));
    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    context.startActivity(openInChooser);

但我只能通过脸谱分享图像(或图像),并且可以通过任何一个intentList共享图像。有些人可以帮助我或回答我的问题。提前致谢

ANswer是:

Intent shareIntent = null;
            try {
                if (imageUris.size() > 1) {
                    shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                    shareIntent.putParcelableArrayListExtra(
                            Intent.EXTRA_STREAM, imageUris);
                    shareIntent.setType("image/*");

                    shareIntent.setClassName("com.google.android.apps.plus",
                            "com.google.android.libraries.social.gateway.GatewayActivity");

                    startActivity(shareIntent);
                } else {
                    shareIntent = ShareCompat.IntentBuilder
                            .from(getActivity())
                            .setType("image/*")

                            .setStream(imageUris.get(0))
                            .getIntent()
                            .setClassName("com.google.android.apps.plus",
                                    "com.google.android.libraries.social.gateway.GatewayActivity");
                    startActivity(shareIntent);
                }
            } catch (ActivityNotFoundException e) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("https://plus.google.com/" + "profile"
                                + "/posts")));
            }
            break;

0 个答案:

没有答案