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"));
Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With