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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…