微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

分享音频 android 11

如何解决分享音频 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 举报,一经查实,本站将立刻删除。