我保存动画文件并与帮助下一个代码共享:
try {
//create an temp file in app cache folder
File outputFile = new File(getCacheDir(), "animation" + ".gif");
FileOutputStream outPutStream = new FileOutputStream(outputFile);
//Saving the resource GIF into the outputFile:
InputStream is = getResources().openRawResource(getAnimationDrawableIdByMediaId(mPickedAnimationId));
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int current = 0;
while ((current = bis.read()) != -1) {
baos.write(current);
}
FileOutputStream fos = new FileOutputStream(outputFile);
fos.write(baos.toByteArray());
//
outPutStream.flush();
outPutStream.close();
//share file
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outputFile));
shareIntent.setType("image/gif");
startActivity(Intent.createChooser(shareIntent, "Share"));
}
catch (Exception e) { Toast.makeText(this, "error", Toast.LENGTH_LONG);}
但是我注意到在Telegram中这个动画的背景是白色的,但在Viber中它是黑色的。有没有办法设置自定义背景颜色?也许还有其他实现。