skip to Main Content

I not have idea how to share the sound on messenger.
I imported api facebook but I kept going.

Forgive me for my English,

    bt = (Button)findViewById(R.id.share1);
    bt.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v) {

            if (ContextCompat.checkSelfPermission(MainActivity.this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {

                String mediaPath = copyFiletoExternalStorage(R.raw.numer_1, "numer_1.mp3");

                /messenger send code *.*/


            } else {
                requestStoragePermission();
            }

        }
    });

2

Answers


  1.    String filePath = Environment.getExternalStorageDirectory().getPath()
                + "<file_Name>";
        Uri uri = Uri.parse(filePath);
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("audio/*");
        share.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(share, "Share Audio File"));
    

    It will launch the app which handles ACTION_SEND and you need to select messaging apps.

    Login or Signup to reply.
  2. Ok I have an answer.

    But it’s not to be a permanent answer.

    I’ve been to this media types pages, where official audio types are mentionned. I didn’t see mp3 on the list.

    here : https://www.iana.org/assignments/media-types/media-types.xhtml#audio
    (link given by google on this page : https://developer.android.com/training/sharing/send#java)

    so I converted my mp3 to aac( figuring on the page).

    and finally changed :

    intent.setType("audio/*");
    

    to :

    intent.setType("audio/aac");
    

    Now sending to messenger works perfectly. but still problems when sharing on whatsapp or on gmail…

    But if you only aim Messenger, then here is an alternative 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search