TweetComposer.Builder

时间:2016-07-05 08:49:05

标签: android twitter twitter-fabric

我正在使用面料来撰写图片和文字推文。

logcat的:

E / TwitterImage:https://458fbec5cf61223e14d9-6f3259da71af87ee4df772aff14bfdf0.ssl.cf5.rackcdn.com/temp_photo.jpg

UsersPostAdapter.java:

    Log.e("TwitterImage", ""+strShareImageUrl);

    Uri uri =  Uri.parse(strShareImageUrl);

    TweetComposer.Builder builder = new TweetComposer.Builder(context)
            .text(strShareText)
            .image(uri);
    builder.show();

我可以在分享时在推特窗口中获取文字。但是在推特窗口中无法显示图像。

我在推特窗口中以image could not be located进行祝酒。只显示文字。

1 个答案:

答案 0 :(得分:0)

图像Uri应该是本地文件的文件Uri(即file:// absolute_path scheme)。

使用Fresco你可以这样做

final DataSource<CloseableReference<PooledByteBuffer>> dataSource =
               ImagePipelineFactory.getInstance().getImagePipeline().fetchEncodedImage(ImageRequest.fromUri(Constants.DEFAULT_LOGO), this);

    DataSubscriber<CloseableReference<PooledByteBuffer>> dataSubscriber =
            new BaseDataSubscriber<CloseableReference<PooledByteBuffer>>() {
                @Override
                protected void onNewResultImpl(
                        DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
                    if (!dataSource.isFinished()) {
                        return;
                    }

                    CloseableReference<PooledByteBuffer> imageReference = dataSource.getResult();
                    if (imageReference != null) {
                        FileOutputStream fileOutputStream = null;
                        PooledByteBufferInputStream pooledByteBufferInputStream;
                        try {
                            pooledByteBufferInputStream = new PooledByteBufferInputStream(imageReference.get());
                            // write the inputStream to a FileOutputStream
                            File tempFile = AndroidUtils.createImageFile();

                            fileOutputStream = new FileOutputStream(tempFile);

                            int read = 0;
                            byte[] bytes = new byte[1024];

                            while ((read = pooledByteBufferInputStream.read(bytes)) != -1) {
                                fileOutputStream.write(bytes, 0, read);
                            }

                            startTwitterIntent(tempFile);

                        } catch (MalformedURLException e) {
                            AnalyticsManager.logError(e);
                            finish();
                        } catch (IOException e) {
                            e.printStackTrace();
                        } finally {
                            CloseableReference.closeSafely(imageReference);
                            imageReference = null;
                            dataSource.close();
                        }
                    }
                }

                @Override
                protected void onFailureImpl
                        (DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
                    Throwable t = dataSource.getFailureCause();
                    AnalyticsManager.logError(t);
                }
            };

    dataSource.subscribe(dataSubscriber, UiThreadImmediateExecutorService.getInstance());

希望有所帮助