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?
I got the solution for executing following code after research:
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: