How to share a file in Android programmatically

Renjith Krishnan picture Renjith Krishnan · Apr 12, 2014 · Viewed 16.3k times · Source

I want to share a file(.pdf,.apk etc) using share Intent, I searched google but I find only the code for sharing Image

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

Answer

Gabe Sechan picture Gabe Sechan · Apr 12, 2014

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 */*