用Intent分享图片到Twitter

如果正常使用intent分享一个数据或者一个图片应该是这样的

try {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setClassName(packageName, activityInfoName);
    if (TextUtils.isEmpty(data.get(ShareEntity.KEY_IMAGE_URL))) {
        shareIntent.setType("text/plain");
    } else {
        shareIntent.setType("image/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(data.get(ShareEntity.KEY_IMAGE_URL)));
    }
    shareIntent.putExtra(Intent.EXTRA_TEXT, data.get(ShareEntity.KEY_TITLE) + "\n" + data.get(ShareEntity.KEY_DESCRIPTION));
    context.startActivity(shareIntent);
} catch(Exception e) {
    e.printStackTrace();
}  

但如果我这个image不是在本地的FIle话到Twitter客户端会显示图片无法加载(估计只是现在的情况,这个也没办法保证变不变)

Picasso.with(ShareActivity.this).load(imageUrl).into(new Target() {@Override public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
        new Thread(new Runnable() {@Override public void run() {
                FileUtils.saveBitmap2File(bitmap, FileUtils.getShareImageFilePath(), true);
                mShareData.put(ShareEntity.KEY_IMAGE_URL, FileUtils.getShareImageFilePath());
                runOnUiThread(new Runnable() {@Override public void run() {
                        hideLoadingDialog();
                        SNSManager.getInstance().shareToForeign(ShareActivity.this, packageName, appName, mShareData);
                    }
                });
            }
        }).start();
    }

    @Override public void onBitmapFailed(Drawable errorDrawable) {

}

    @Override public void onPrepareLoad(Drawable placeHolderDrawable) {

}
});

这就是简单的处理的办法吧,总之是要把东西存为文件

你可能感兴趣的:(用Intent分享图片到Twitter)