为什么在 Android 10 OS 中共享内容时不显示共享托盘标记的 Intent LinkedIn 图标

Why the Share Tray Labeled Intent LinkedIn Icon not displayed while sharing content in Android 10 OS

我正在使用共享托盘通过 Intent 共享来共享 plain/text 从中读取包名称并在标记的 Intent 中过滤应用程序。某些应用程序显示在该列表中,并且在该列表中也有 Linkedin 包名称,但未在共享托盘中显示 Linkedin 图标。为什么那个图标不显示?

设备:三星 Galaxy S10
OS: Android 版本 10

我试过的代码

 PackageManager pm=getActivityContext.getPackageManager();
        Intent sendIntent=new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");

        Intent receiver=new Intent(getActivityContext, UserSelectedShareBroadcast.class);
        PendingIntent pendingIntent=PendingIntent.getBroadcast(getActivityContext, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent openInChooser=Intent.createChooser(emailIntent, "Choose", pendingIntent.getIntentSender());
        List<ResolveInfo> resInfo=pm.queryIntentActivities(sendIntent, 0);
        List<LabeledIntent> intentList=new ArrayList<>();

        Intent externalEmailIntent=new Intent(getActivityContext, ExternalEmailShareActivity.class);
        externalEmailIntent.putExtra("programId", programId);
        intentList.add(new LabeledIntent(externalEmailIntent, "packagename", "Email to", R.drawable.ic_mail_outline));

        for (int i=0; i < resInfo.size(); i++) {
            // Extract the label, append it, and repackage it in a LabeledIntent
            ResolveInfo ri=resInfo.get(i);
            String packageName=ri.activityInfo.packageName;
            //Enabled Tweet sharing
            /*if (packageName.contains("twitter")) {
                emailIntent.setPackage(packageName);
            } else*/
            if (packageName.contains("twitter") || packageName.contains("facebook") ||
                    packageName.contains("whatsapp") || packageName.contains("linkedin") ||
                    packageName.contains("com.google.android.apps.docs") ||
                    packageName.contains("com.google.android.gm") ||
                    packageName.contains("com.Slack")) {
                Intent intent=new Intent();
                try {
                    intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
                    intent.setAction(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    //intent.setType("text/plain/image");
                    if (packageName.contains("twitter")) {
                        intent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("facebook")) {
                        // Warning: Facebook IGNORES our text. They say "These fields are intended for users to express themselves. Pre-filling these fields erodes the authenticity of the user voice."
                        // One workaround is to use the Facebook SDK to post, but that doesn't allow the user to choose how they want to share. We can also make a custom landing page, and the link
                        // will show the <meta content ="..."> text from that page with our link in Facebook.
                        intent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("whatsapp")) {
                        intent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("linkedin")) {
                        intent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("com.google.android.apps.docs")) {
                        intent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("com.Slack")) {
                        intent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    }else if (packageName.contains("android.gm")) {
                    // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                    //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                    intent.putExtra(Intent.EXTRA_SUBJECT, str_title);
                    intent.setType("message/rfc822");
                    intent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    Uri uri = Uri.parse(publicThumbnail);
                    intent.putExtra(Intent.EXTRA_STREAM, uri);
                }

                    intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                  intent=null;
                }
            }
        }

        // convert intentList to array

        LabeledIntent[] extraIntents=intentList.toArray(new LabeledIntent[intentList.size()]);

        openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
        getActivityContext.startActivityForResult(openInChooser, REQUEST_SHARED_URL);

我对您的代码进行了一些更改,以便通过 Intent 在 LinkedIn 上创建 post。请检查下面给出的我的代码。我已经在 android 10 os 中进行了测试,并且工作正常。希望能帮助到你。

 private void shareTray(){
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(Intent.EXTRA_TEXT, sharedURL);

    Intent receiver=new Intent(getActivityContext, UserSelectedShareBroadcast.class);
    PendingIntent pendingIntent=PendingIntent.getBroadcast(getActivityContext, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);

    PackageManager pm=getActivityContext.getPackageManager();
    Intent openInChooser=Intent.createChooser(sharingIntent, "Choose", pendingIntent.getIntentSender());
    List<ResolveInfo> resInfo=pm.queryIntentActivities(sharingIntent, 0);
    List<LabeledIntent> intentList=new ArrayList<>();

    Intent externalEmailIntent=new Intent(getActivityContext, ExternalEmailShareActivity.class);
            externalEmailIntent.putExtra("INBOX", "Inbox");
    intentList.add(new LabeledIntent(externalEmailIntent, "yourpackagename", "Email to", R.drawable.ic_mail_outline));

    for (int i=0; i < resInfo.size(); i++) {
        ResolveInfo ri=resInfo.get(i);
        String packageName=ri.activityInfo.packageName;
        if (packageName.contains("twitter")) {
            sharingIntent.setPackage(packageName);
        } else{
            if (packageName.contains("twitter") || packageName.contains("facebook") ||
                    packageName.contains("whatsapp") || packageName.contains("linkedin") ||
                    packageName.contains("com.google.android.apps.docs") ||
                    packageName.contains("com.google.android.gm") ||
                    packageName.contains("com.Slack")) {
                Intent shareIntent=new Intent();
                try {
                    shareIntent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
                    shareIntent.setAction(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    //shareIntent.setType("text/plain/image");
                    if (packageName.contains("twitter")) {
                        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("facebook")){shareIntent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("whatsapp")) {
                        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("linkedin")) {
                        shareIntent.putExtra(Intent.EXTRA_TITLE, sharedURL);
                        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("com.google.android.apps.docs")) {
                        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    } else if (packageName.contains("com.Slack")) {
                        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                    }else if (packageName.contains("android.gm")) {
                        // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                        shareIntent.putExtra(Intent.EXTRA_SUBJECT, str_title);
                        shareIntent.setType("message/rfc822");
                        shareIntent.putExtra(Intent.EXTRA_TEXT, sharedURL);
                        Uri uri = Uri.parse(publicThumbnail);
                        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
                    }

                    intentList.add(new LabeledIntent(shareIntent, packageName, ri.loadLabel(pm), ri.icon));
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    shareIntent=null;
                }
            }
        }

    }
    // convert intentList to array
    LabeledIntent[] extraIntents=intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    getActivityContext.startActivityForResult(openInChooser, REQUEST_SHARED_URL);

}

快乐编码..