How to send a GIF in Whatsapp programmatically on Android?

1

How can I send a GIF located in the internal memory of the My application directly to WhatsApp programmatically?

    
asked by anonymous 29.11.2017 / 15:43

1 answer

1

As this answer link can do this (but of course it will depend on the WhatsApp version)

private void shareGif(String resourceName){

    String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    String fileName = "sharingGif.gif";

    File sharingGifFile = new File(baseDir, fileName);

    try {
        byte[] readData = new byte[1024*500];
        InputStream fis = getResources().openRawResource(getResources().getIdentifier(resourceName, "drawable", getPackageName()));

        FileOutputStream fos = new FileOutputStream(sharingGifFile);
        int i = fis.read(readData);

        while (i != -1) {
            fos.write(readData, 0, i);
            i = fis.read(readData);
        }

        fos.close();
    } catch (IOException io) {
    }

    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("image/gif");
    Uri uri = Uri.fromFile(sharingGifFile);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(shareIntent, "Share Emoji"));
}
  

I have not tested it yet.

    
29.11.2017 / 16:04