在Android中共享GIF

在Android中共享GIF,android,gif,Android,Gif,我正在开发一个Android应用程序,其中我必须实现与其他消息传递应用程序共享GIF的功能 为此,我将存储在一个临时文件中,并通过intent传递文件的url。我的gif存储为可绘制的格式。因此,在检索它时,我使用带有位图.Compress的FileOutputStream。由于这而不是GIF,我得到了一个stil图像 此外,我还尝试在不压缩的情况下将位图转换为字节数组,但在这种情况下,我的图像没有显示出来 共享gif的我的代码: int drawableId = gridItemList.ge

我正在开发一个Android应用程序,其中我必须实现与其他消息传递应用程序共享GIF的功能

为此,我将存储在一个临时文件中,并通过intent传递文件的url。我的gif存储为可绘制的格式。因此,在检索它时,我使用带有位图.Compress的FileOutputStream。由于这而不是GIF,我得到了一个stil图像

此外,我还尝试在不压缩的情况下将位图转换为字节数组,但在这种情况下,我的图像没有显示出来

共享gif的我的代码:

int drawableId = gridItemList.get(position);
Bitmap contentToShare = BitmapFactory.decodeResource(getResources(),   drawableId);                
try {
    File cachePath=new File(getApplicationContext().getFilesDir(),"content");
    cachePath.mkdirs();
    FileOutputStream stream=new FileOutputStream(cachePath+"/anim.gif");
    contentToShare.compress(Bitmap.CompressFormat.PNG, 100, stream);
    stream.close();
    File imagePath = new File(getApplicationContext().getFilesDir(), "content");
    File newFile = new File(imagePath,"anim.gif");
    Uri contentURI=FileProvider.getUriForFile(getApplicationContext(),getPackageName()+".fileprovider",newFile);
    if(contentURI!=null)    {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, contentURI);
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shareIntent.setType("image/gif");
        startActivity(shareIntent);
    }
}catch (Exception e)    {
    Log.e("Exception",e.toString());
}

PS:共享jpeg和png效果很好。

使用Glide库显示GIF

在你的毕业典礼上:

compile 'com.github.bumptech.glide:glide:3.7.0'
要编写的代码:

String gifUrl = "http://i.kinja-img.com/gawker-media/image/upload/s--B7tUiM5l--/gf2r69yorbdesguga10i.gif";

Glide  
    .with( context )
    .load( gifUrl )
    .into( imageViewGif );

发布您的代码…使用Glide库显示您的gif我已经在使用Glide从drawable加载gif。但是我不能分享gif