分享音频文件到 WhatsApp(文件格式不受支持错误)。

huangapple 未分类评论63阅读模式
标题翻译

share audio file with whatsapp (file format not supported error)

问题

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'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

 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();
                    }
                });

分享音频文件到 WhatsApp(文件格式不受支持错误)。

答案1

得分: 0

我不太确定但请尝试使用这个意图

Intent share = new Intent(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, "分享音频文件"));
英文翻译

I am not sure but try to use this Intent

Intent share = new Intent(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"));

huangapple
  • 本文由 发表于 2020年3月4日 07:37:23
  • 转载请务必保留本文链接:https://java.coder-hub.com/60517093.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定