分享音频 android 11

问题描述

嗨,我正在 android 11 中共享音频,但在 gmail 中出现“无法附加文件错误

我正在为 android 11 使用以下代码

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {

                        File tempFile = null;
                        try {
                                tempFile = File.createTempFile("extractaudio",".mp3",context.getExternalCacheDir());
                                FileWriter fw = new FileWriter(tempFile);
                                FileReader fr = new FileReader(sendFile);
                                int c = fr.read();
                                while (c != -1) {
                                        fw.write(c);
                                        c = fr.read();
                                }
                                fr.close();
                                fw.flush();
                                fw.close();
                                Intent sendIntent = new Intent(Intent.ACTION_SEND);
                                sendIntent.setType("audio/*");
                                sendIntent.putExtra(Intent.EXTRA_SUBJECT,"Video to audio");
                                sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(tempFile));
                                sendIntent.putExtra(Intent.EXTRA_TEXT,"Enjoy the audio.");
                                sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                sendIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                                startActivityForResult(Intent.createChooser(sendIntent,""),10);
                        } catch (IOException e) {
                                e.printstacktrace();
                        }

                }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)