图片无法在Twitter上加载

时间:2013-07-17 13:38:18

标签: android android-intent twitter sharing

我正在尝试通过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());
     }
}

任何帮助将不胜感激谢谢

2 个答案:

答案 0 :(得分:2)

这似乎是推特应用上的一个错误。尝试在Android 4.3的Nexus 4上将图库分享到Twitter时出现同样的错误。奇怪的是,在我今天进行升级之前,这在4.2.2上有效。

答案 1 :(得分: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;
                }
            }


        }