我尝试通过手动启动Google驱动器(安装在设备上)从我的Android应用程序上传文件.我尝试使用Intent.createChooser它来发送文件附件,并且工作正常.但我需要上传特定意图的文件(例如Dropbox,仅限Google云端硬盘).所以我更改了代码并尝试按以下方式将文件上传到Google云端硬盘,但没有成功,只有Google云端硬盘应用在设备上打开,没有上传文件:
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);
Run Code Online (Sandbox Code Playgroud)
我们可以通过手动打开意图上传PDF文件吗?