skip to Main Content

I’m using this code for some years now and it worked fine:

final Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    sharingIntent.setType("audio/mpeg");
    sharingIntent.putExtra(Intent.EXTRA_STREAM,
        SoundProvider.getUriForSound(getContext(), sound));

    getActivity()
        .startActivity(Intent.createChooser(sharingIntent,
            getContext().getString(R.string.share)));

My SoundProvider generates a URI that starts with content:// which is picked up by a FileProvider (actually the same SoundProvider). This provider reads an audio file from my raw folder.

The sounds was playable directly in WhatsApp (and not a generic file) and shown with the correct title from the ID3 tags.

This has worked flawlessly and still does with Telegram/Dropbox etc. but up until a recent WhatsApp update from a few months ago it fails with the message “Sharing failed please try again”.

Is anyone aware of any changes made by WhatsApp and has encountered something similar?

2

Answers


  1. Chosen as BEST ANSWER

    I had to work around this by copying the sounds to the external-files-dir.

    I don't know why whatsapp suddenly doesn't accept files from the raw directory served by a FileProvider anymore while other apps still do without any problems.


  2. Try this:

    Uri uri = Uri.parse(audioPath);
    Intent shareIntent = new Intent();
    shareIntent.setType("audio/*");
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search