0

I have create a pdf and now want to upload it on Google drive and Dropbox but not able to upload. i have used the following code:

    Uri pdfUri = Uri.parse("file://" + File.separator+ "sdcard" + File.separator + "A****" File.separator + "A****.pdf");
    Intent shareIntent = ShareCompat.IntentBuilder.from(TripHome.this).setText("Share PDF doc").setType("application/pdf").setStream(pdfUri).getIntent().setPackage("com.google.android.apps.docs");
    startActivity(shareIntent);
Ashfaque
  • 1,254
  • 1
  • 22
  • 38
Manoj Tarkar
  • 438
  • 4
  • 9

1 Answers1

0

Take a look at user2459928's the answer here: Android Launch a Google Drive application from another application not uploaded file

Additionally, I would highly suggest wrapping the startActivity() in a try catch block just in case the user does not have the app that you are trying to launch installed on their device.

Uri pdfUri = Uri.fromFile(new File("path/to/file"));

try {
    Intent shareIntent = ShareCompat.IntentBuilder.from((Activity) context)
                .setText("Share PDF file")
                .setType("application/pdf")
                .setStream(pdfUri)
                .getIntent()
                .setPackage("com.google.android.apps.docs");
    context.startActivity(shareIntent);
}catch (Exception e){
    e.printStackTrace();
    // show a Toast or messag saying "activity not found" or "application not installed on this device"
}
Community
  • 1
  • 1
ClayHerendeen
  • 187
  • 1
  • 4
  • 15