1

When I share animate gif to Twitter by using Intent, Twitter makes it static image.

It works to share to Facebook Messenger.

How to create an animated GIF from JPEGs in Android (development)

I use this class to create Animated gif. Can anyone help me?

Here is my code below.

public byte[] generateGIF(ArrayList<Bitmap> bitmaps) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    AnimatedGifEncoder encoder = new AnimatedGifEncoder();
    encoder.start(bos);
    for (Bitmap bitmap : bitmaps) {
        encoder.addFrame(bitmap);
    }
    encoder.finish();
    return bos.toByteArray();
}


private void shareGif (byte[] bytes,String fileName) {

    try {
        File file = new File(getApplicationContext().getCacheDir(), fileName + ".gif");

        FileOutputStream fOut = new FileOutputStream(file);
        fOut.write(bytes);
        fOut.close();

        file.setReadable(true, false);
        final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        intent.setType("image/gif");
        startActivity(Intent.createChooser(intent , "Send image using.."));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Community
  • 1
  • 1

0 Answers0