Android Launch a Google Drive application from another application not uploaded file
10,631
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:
- com.dropbox.android = Dropbox
- com.android.bluetooth = Bluetooth
- com.android.email = Email
- com.google.android.gm = Gmail
- com.microsoft.skydrive = Skydrive
- com.google.android.apps.docs = Googledrive
For gmail sharing we need to use following type of code:
Uri zipUri = Uri.parse("file://sdcard/sdcard0/test.zip");
String[] emailArr = {"[email protected]"};
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);
Author by
Admin
Updated on June 11, 2022Comments
-
Admin almost 2 years
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("com.google.android.apps.docs"); intent.setType("application/pdf"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/sdcard0/test.pdf")); intent.putExtra(Intent.EXTRA_SUBJECT, "attach a file test"); intent.addCategory(Intent.ACTION_ATTACH_DATA); startActivity(intent);
Can we upload a PDF file by opening the intent manually as above?
-
Ravi almost 10 yearsgetting this error. Unable to start activity ComponentInfo{com.example.driveshareintent/com.example.driveshareintent.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=application/pdf flg=0x80001 pkg=com.google.android.apps.docs (has clip) (has extras) }
-
Roel about 9 years@Ravi: You have to have the application installed: so allways check for this exception! (or you used a not existing package name)
-
Khizar Hayat almost 7 yearsIf i can upvote 100 times within an hour i will spend one hour for this answer..... awesome man
-
Khizar Hayat almost 7 yearsIs it working in marshmallow and plus ? i am getting security exception can you please help
-
Khizar Hayat almost 7 yearsI tried it will only work for android 6.0 and above, when you make your own provider. for others help you can see this stackoverflow.com/questions/18249007/…
-
A.Sanchez.SD about 3 yearsIs it possible to launch into Google Docs to use their scan feature ?