2016-07-05 34 views
0

我使用織物來撰寫圖像和文本推文。TweetComposer.Builder中未顯示Http圖像

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(); 

我能得到在Twitter的窗口中的文本,而sharing.But圖片不能在Twitter窗口中顯示。

我在Twitter窗口中獲得烤麪包作爲image could not be located。僅顯示文本。

回答

0

圖像Uri應該是一個文件Uri(即file:// absolute_path scheme)到本地文件。

使用壁畫ü可以這樣做

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()); 

希望它可以幫助