如何在Android中以编程方式在Whatsapp中分享GIF图像?

时间:2016-09-23 08:54:58

标签: android whatsapp

WhatsApp已添加新功能显示GIF。

如果有人知道如何在whatsapp中分享GIF,请告诉我

2 个答案:

答案 0 :(得分:1)

试试这个......

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"));
}

在whatsapp上分享gif

/*  Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT,title + "\n\nLink : " + link );
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(sharePath));
shareIntent.setType("image/*");
startActivity(shareIntent);*/

答案 1 :(得分:1)

您只需要将图像意图的类型设置为gif,如下所示

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/gif");

有关更多文档,请参阅How to share gif image to whatsapp in android