How to share a file in Android programmatically

You use the same code, you just change the MIME type for the type of data you wish to share. If you wish to share anything regardless of type, use */*


To keep your code pragmatic, use ShareCompat class:

ShareCompat.IntentBuilder.from(this)
        .setStream(uri)
        .setType(URLConnection.guessContentTypeFromName(file.getName()))
        .startChooser();

This will help you

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("*/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share using"));

Tags:

Android

Share