如何使用意图共享将gif图像共享到可用的应用程序? [英] how to share gif images using intent sharing to available apps?
本文介绍了如何使用意图共享将gif图像共享到可用的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想与可用的应用程序(如whatsapp)共享.gif,但无法在我的可绘制资源中获取gif的有效Uri.
i want working on sharing .gif with available apps like whatsapp, but unable to get valid Uri of gif present in my drawable resource.
Uri path = Uri.parse("android.resource://my_package_name/" + R.drawable.gif_1);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/gif");
shareIntent.putExtra(Intent.EXTRA_STREAM, path);
在共享图片方面有很多解决方案,但在gif共享方面没有解决方案,请帮忙
there is lot of solution on sharing images but no solution on gif sharing, Please help
推荐答案
我找到了答案,我刚刚创建了一个扩展名为.gif的文件,它对我有用.请参见下面的代码:
I found my answer, I just created a file with a .gif extension and it worked for me. See the code below:
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"));
}
这篇关于如何使用意图共享将gif图像共享到可用的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文