priojeet priyom
priojeet priyom

Reputation: 908

how to share audio through share it from another app

I want to share audio file in different social apps from my app. I am using following code to share audios. it is working well for whatsapp but not working for shareit. shareit app opens but fails to retrieve the file and says "Sending this type of content is not supported". the file was of "mp3" format. I could share the file from file manager using the android generic share option and then selecting shareit.

public void shareAudio(String packageName, String platformName) {
    checkAndPauseAudioPlayer();
    try {
        //Copy file to external ExternalStorage.
        String mediaPath = audioFilePath;

        Intent shareMedia = new Intent(Intent.ACTION_SEND);

        shareMedia.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        //set application package
        shareMedia.setPackage(packageName);
        shareMedia.setType("audio/*");
        //set path of media file in ExternalStorage.
        shareMedia.putExtra(Intent.EXTRA_STREAM, Uri.parse(mediaPath));
        startActivity(Intent.createChooser(shareMedia, platformName+" Is Not Installed!"));
    } catch (Exception e) {
        showSnackBar("Please Install "+platformName+" First!",Snackbar.LENGTH_LONG);
    }
}

Upvotes: 1

Views: 473

Answers (1)

Dhara Jani
Dhara Jani

Reputation: 461

add permission in manifest file :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Upvotes: 1

Related Questions