android - Google+ 分享对话框显示错误图片

标签 android google-plus

我正在尝试使用此方法Google+ 上分享图片和标题:

share(com.google.android.apps.plus, img, title);
====================================
private void share(String type, int imgResId, String title) {
        boolean found = false;
        Intent share = new Intent(android.content.Intent.ACTION_SEND);
        share.setType("image/jpeg");

        // gets the list of intents that can be loaded.
        List<ResolveInfo> resInfo = context.getPackageManager()
                .queryIntentActivities(share, 0);
        if (!resInfo.isEmpty()) {
            for (ResolveInfo info : resInfo) {

                if (info.activityInfo.packageName.toLowerCase(
                        Locale.ENGLISH).contains(type)
                        || info.activityInfo.name.toLowerCase(
                                Locale.ENGLISH).contains(type)) {
                    Log.d("pack", info.toString());
                    share.putExtra(Intent.EXTRA_SUBJECT, "subject");
                    share.putExtra(Intent.EXTRA_TEXT, title);
                    share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Helper
                            .saveFile(context, imgResId))); // Optional,
                                                            // just if you
                                                            // wanna share
                                                            // an image.
                    share.setPackage(info.activityInfo.packageName);
                    found = true;
                    break;
                }
            }
            if (!found)
                return;

            context.startActivity(Intent.createChooser(share, "Select"));
        }
}

Google+ 分享对话框 出现时它显示了错误的图片(我第一次尝试在 Google+ 上分享的图片)。我尝试更改图片 资源 id 但仍然是相同的错误图像。

最佳答案

我在尝试为不同的文件重用 URI 时遇到了同样的问题,某处似乎有一个图像缓存,它没有注意到图像发生了变化。

我通过为新图像生成不同的 URI 来“修复”它(在您的情况下,每次都使用唯一的文件名)。更好的解决方案是使该缓存无效,但我不知道如何(或是否)可以做到这一点。

关于android - Google+ 分享对话框显示错误图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33322010/

相关文章:

android - Activity 结果后此 NavController 未知的导航目的地

android - 无法使 Android Plot 在 Android Studio 中工作

ios - 如何在 iOS 的一个应用程序中使用 Google Drive 和 Google Plus API?

asp.net - Google+ 与 ASP.NET 集成

twitter-bootstrap - 如何使 Google Plus 徽章具有响应性?

android - 使用 Robolectric 测试带有 intent extras 的服务的启动?

android - Activity 工具栏中的 SearchView 和过滤器以分段

android - Google Play Games Services Leaderboard API,无法查看其他玩家的分数

java - +1 按钮的应用 URL

java - 在 Android 中使用整数 ArrayList