I tried to upload a file from my android application by manually launching Google drive (installed on the device). I tried this to send using Intent.createChooser
I got the solution for executing following code after research:
import android.support.v4.app.ShareCompat;
Uri pdfUri = Uri.parse("file://sdcard/sdcard0/test.pdf");
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setText("Share PDF doc")
.setType("application/pdf")
.setStream(pdfUri )
.getIntent()
.setPackage("com.google.android.apps.docs");
startActivity(shareIntent);
Similarly we can use for other share intent and the corresponding package name of few intents are as below:
For gmail sharing we need to use following type of code:
Uri zipUri = Uri.parse("file://sdcard/sdcard0/test.zip");
String[] emailArr = {"test@gmail.com"};
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setText("Share ZIP doc")
.setType("application/zip")
.setEmailTo(emailArr)
.setStream(zipUri)
.setSubject("Share zip doc")
.setText("Sent with email app.")
.getIntent()
.setPackage("com.google.android.gm");
startActivity(shareIntent);