简体   繁体   English

与 whatsapp 共享音频文件(文件格式不支持错误)

[英]share audio file with whatsapp (file format not supported error)

I'm trying to make a button for sharing an audio file.I get the file format not supported error.I tried all types but always gave the same error(audio/mpeg,audio/aac,audio/wav,audio/ogg,audio/midi,audio/x-ms-wma) here my codes我正在尝试制作一个用于共享音频文件的按钮。我得到了文件格式不受支持的错误。我尝试了所有类型,但总是出现相同的错误(音频/mpeg、音频/aac、音频/wav、音频/ogg、音频/midi,音频/x-ms-wma)这里是我的代码

 button.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        File f = new File("ses.mp3");
                        Uri uri = Uri.parse("file://" + f.getAbsolutePath());
                        Intent share = new Intent(Intent.ACTION_SEND);
                        share.putExtra(Intent.EXTRA_STREAM, uri);
                        share.setType("audio/mp3");
                        share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        mactivity.startActivity(Intent.createChooser(share, "Share audio File"));

                        Toast.makeText(getApplicationContext(), "Song Shared Successfully", Toast.LENGTH_SHORT).show();
                    }
                });

在此处输入图片说明

I am not sure but try to use this Intent我不确定但尝试使用此 Intent

Intent share = new Intent(Intent.ACTION_SEND);意图份额 = 新意图(Intent.ACTION_SEND);

   share.setType("*/*");

   File imageFileToShare = new File(f.getAbsolutePath());

    Uri uri= FileProvider.getUriForFile
            (mactivity,mactivity.getPackageName()+".provider",imageFileToShare);

    share.putExtra(Intent.EXTRA_STREAM, uri);

mactivity.startActivity(Intent.createChooser(share, "Share audio File")); mactivity.startActivity(Intent.createChooser(share, "Share audio File"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM