0

我正在尝试通过 twitter 分享图像,facebook 一切正常,但 twitter 图像无法加载!我不知道为什么这是我的代码:

enter code here


public void share(String nameApp) 
{
    try
    {
        List<Intent> targetedShareIntents = new ArrayList<Intent>();
        Intent share = new Intent(android.content.Intent.ACTION_SEND);
        share.setType("image/jpg");
        List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
        if (!resInfo.isEmpty())
        {
            for (ResolveInfo info : resInfo) 
            {
                Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
                targetedShare.setType("image/jpg"); // put here your mime type
                if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) {
                    targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo");
                 targetedShare.putExtra(Intent.EXTRA_TEXT,"This photo is created by Me");
                 ClassGlobal.selectedPagerURLs = new String[ClassGlobal.selectedAlbum.album_Thumbnail_Images.size()];
                //This path worked fine with facebook sdk but in twitter everything is fine except the image could not be loaded    
                    Uri screenshotUri = Uri.parse(ClassGlobal.selectedPagerURLs[currentItem]=ClassGlobal.selectedAlbum.album_Thumbnail_Images.get(currentItem).thumbnail_Url);

                    targetedShare.putExtra(Intent.EXTRA_STREAM,screenshotUri);
                    targetedShare.setPackage(info.activityInfo.packageName);
                    targetedShareIntents.add(targetedShare);
                }
            }
            Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
            startActivity(chooserIntent);
        }
    }
    catch(Exception e)
     {
         Log.v("VM","Exception while sending image on" + nameApp + " "+  e.getMessage());
     }
}

任何帮助将不胜感激谢谢

4

2 回答 2

2

这似乎是 Twitter 应用程序上的一个错误。尝试在装有 Android 4.3 的 Nexus 4 上将图片从画廊分享到 Twitter 时,我遇到了同样的错误。奇怪的是,在我今天升级之前,这在 4.2.2 上有效。

于 2013-07-26T21:36:33.017 回答
0
 Uri imagePathUri = Uri.parse("android.resource://com.example.test.social_integration/"+R.drawable.share);
            Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.share);
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
            String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, "Title", null);
            Uri imageUri = Uri.parse(path);
            Intent shareIntent = new Intent();
            shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_TEXT, "Test_Tweet");
            shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
            shareIntent.setType("image/jpeg");

            PackageManager pm = v.getContext().getPackageManager();
            List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
            for (final ResolveInfo app : activityList)
            {
                if (app.activityInfo.name.contains("twitter"))
                {
                    final ActivityInfo activity = app.activityInfo;
                    final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                    shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                    shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                    shareIntent.setComponent(name);
                    v.getContext().startActivity(shareIntent);
                    break;
                }
            }


        }
于 2015-07-13T13:41:56.610 回答