2

I'm developing an application that has to share a mp3 file via whatsapp.

My code at this moment is the following:

final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("audio/mp3");
shareIntent.setPackage("com.whatsapp");
Uri recurso = Uri.parse("android.resource://com.yayo.yayobotonera/" + R.raw.audio1);
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, recurso);
startActivity(Intent.createChooser(shareIntent, getString(R.string.text1)));

I can successfully share via Gmail, for example, but it's not working via whatsapp. Is that a problem of my code or just that whatsapp doesn't allow you to share mp3 files?

Thanks in advance!

user1786381
  • 47
  • 1
  • 4

1 Answers1

-1

Use this::

 final Intent sendIntent  = new Intent(Intent.ACTION_SEND);
                sendIntent.putExtra("sms_body", "bod of sms");
                sendIntent.setType("*/*");
                sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
                final File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.amr");
                Uri uri = Uri.fromFile(file1);
                Log.e("Path", "" + uri);
                sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(sendIntent, ""));
vijay
  • 1,475
  • 2
  • 16
  • 26
  • Not only this is MMS-related, but it is deprecated as of 2020 (```FileUriExposedException```). Downvoting. – xvlaze Aug 09 '20 at 22:51