Android Launch a Google Drive application from another application not uploaded file


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 and its working fine for uploading file attachment. But I need to upload file for specific intent (like Dropbox, Google drive only). So I changed the code and tried to upload a file to Google drive as following ways, but no success, only Google drive app is open on device, no file uploaded:

PackageManager pm = this.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/sdcard0/test.pdf"));
intent.putExtra(Intent.EXTRA_SUBJECT, "attach a file test");

Can we upload a PDF file by opening the intent manually as above?

Best Solution

I got the solution for executing following code after research:


Uri pdfUri = Uri.parse("file://sdcard/sdcard0/test.pdf");                
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
                                     .setText("Share PDF doc")
                                         .setStream(pdfUri )

Similarly we can use for other share intent and the corresponding package name of few intents are as below:

  • = Dropbox
  • = Bluetooth
  • = Email
  • = Gmail
  • = Skydrive
  • = Googledrive

For gmail sharing we need to use following type of code:

Uri zipUri = Uri.parse("file://sdcard/sdcard0/");  
String[] emailArr = {""};              
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
                                  .setText("Share ZIP doc")
                                  .setSubject("Share zip doc")
                                  .setText("Sent with email app.")