java - 以编程方式使用图库(或类似)应用程序打开 gif 文件

标签 java android gif

在“我的应用程序”的其中一项 Activity 中,单击按钮会将 gif 保存到打开图库应用程序时显示的文件夹中。如何使用 Intent 或类似的东西保存后立即打开文件?

这就是我节省的方式:

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File gifFile = new File(mediaStorageDir.getPath() + File.separator +
                    "GIF_"+ timeStamp + ".gif");
FileOutputStream outStream = null;
try{
    outStream = new FileOutputStream(gifFile);
    outStream.write(generateGIF());
    outStream.close();
}catch(Exception e){
    e.printStackTrace();
}

这似乎不起作用:

Uri fileUri = Uri.fromFile(gifFile);
startActivity(new Intent(Intent.ACTION_VIEW, fileUri));

最佳答案

您需要使用 setDataAndType 来传递文件 URI 和数据类型:

Uri fileUri = Uri.fromFile(gifFile);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(fileUri,"image/gif");
startActivity(intent);

关于java - 以编程方式使用图库(或类似)应用程序打开 gif 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31688454/

相关文章:

java - Netbeans Java 中的动画启动屏幕

android - 适用于 Android 的 WebP

android - 通过 Intent 将编辑文本的文本移动到另一个 Activity 会引发异常

bash - 如何在 FFMPEG 的同一命令中使用 -vf 和 -filter_complex

macos - 无法使用 gifify 将 mp4 转换为 gif

java - 如何将fragmentpageradapter中每个tab的图标设置为gif动画?

java - 方法标题中的分号预期错误

java - 在标签android中添加 fragment 的最佳方式是什么

java - 带有负数的数字类型解析函数异常

android - 我想在 Android 中的 Multi AutoCompleteTextView 右侧添加图标