Java 如何通过firebase存储中的intents共享gif文件
我正在firebase的imageView中显示gif文件。 现在我想在用户单击共享按钮时通过意图共享它。 但是我做不到。 我正在使用此代码,但当用户单击应用程序时,应用程序将关闭Java 如何通过firebase存储中的intents共享gif文件,java,android,firebase,android-intent,firebase-storage,Java,Android,Firebase,Android Intent,Firebase Storage,我正在firebase的imageView中显示gif文件。 现在我想在用户单击共享按钮时通过意图共享它。 但是我做不到。 我正在使用此代码,但当用户单击应用程序时,应用程序将关闭 public void sharegif(){ String baseDir = MainActivity.this.getExternalCacheDir() + "/gm_gif_1.gif"; FileOutputStream out = null;
public void sharegif(){
String baseDir = MainActivity.this.getExternalCacheDir() + "/gm_gif_1.gif";
FileOutputStream out = null;
File file = new File(baseDir);
try {
byte[] readData = new byte[1024 * 500];
InputStream fis = getResources().openRawResource(getResources()
.getIdentifier("gm_gif_1.gif", null, null));
FileOutputStream fos = new FileOutputStream(file);
int i = fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
}
baseDir = file.getPath();
Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID +".provider", new File(baseDir));
Intent shareIntent = new Intent();
shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
shareIntent.setType("image/gif");
startActivity(Intent.createChooser(shareIntent, "Share with"));
}
如果你的应用程序崩溃,你不会捕获抛出的异常。请找出并告诉我们。查看日志猫。
catch(IOException io){}
更好:catch(IOException io){io.printStacTrace();Toast(…通知用户..);return;}
您应该为授予读取权限添加一个标志。