I am using the following piece of code to share an audio file located on a device:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://pathToFile"));
intent.setType("audio/*");
activity.startActivity(Intent.createChooser(intent, "Share..."));
Android opens the system Share dialog where you can select an appropriate app to handle the share intent. Audio files get successfully shared with Gmail, WhatsApp, Telegram and Google Drive.
But Messenger shows the following error:
However, when I try to share the same file using Android's Download app, it all works just fine with Messenger.
Why does Messenger not process my share request correctly, while all the other apps do, and what needs to be changed in my code so it would work the same way as sharing from the Download app (so it would work for Messenger)?