In order to get the PDF you'll need to create an activity for this use case that listens for those "sharing" intents.
ShareActivity.java
void onCreate (Bundle savedInstanceState) {
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("application/pdf".equals(type)) {
handlePDF(intent);
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
if (type.startsWith("application/pdf")) {
// Handle multiple pdfs being sent
}
} else {
// Handle other intents, such as being started from the home screen
}
}
void handlePDF(Intent intent) {
Uri pdfUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (pdfUri != null) {
// TODO: Use your server-side here to save.
}
}
And then add this to your AndroidManifest.xml so Android knows what activity to get when they select your application to share to:
<activity android:name=".ui.ShareActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
</activity>