我尝试通过手动启动 Google 驱动器(安装在设备上)从我的 android 应用程序上传文件。我试过这个发送使用Intent.createChooser
和上传文件附件的工作正常。但我需要上传特定意图的文件(如 Dropbox,仅限 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);
我们可以像上面那样通过手动打开意图来上传 PDF 文件吗?