我如何通过 firebase 存储中的意图共享 gif 文件

时间:2021-05-08 06:28:54

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

0 个答案:

没有答案
相关问题