我创建了一个pdf
,现在希望在upload
和Google drive
上Dropbox
,但无法上传。我使用了以下代码:
Uri pdfUri = Uri.parse("file://" + File.separator+ "sdcard" + File.separator + "A****" File.separator + "A****.pdf");
Intent shareIntent = ShareCompat.IntentBuilder.from(TripHome.this).setText("Share PDF doc").setType("application/pdf").setStream(pdfUri).getIntent().setPackage("com.google.android.apps.docs");
startActivity(shareIntent);
答案 0 :(得分:0)
在这里查看 user2459928的答案:Android Launch a Google Drive application from another application not uploaded file
此外,我强烈建议将tryActivity()包装在try catch块中,以防万一用户没有在您的设备上安装您尝试启动的应用程序。
Uri pdfUri = Uri.fromFile(new File("path/to/file"));
try {
Intent shareIntent = ShareCompat.IntentBuilder.from((Activity) context)
.setText("Share PDF file")
.setType("application/pdf")
.setStream(pdfUri)
.getIntent()
.setPackage("com.google.android.apps.docs");
context.startActivity(shareIntent);
}catch (Exception e){
e.printStackTrace();
// show a Toast or messag saying "activity not found" or "application not installed on this device"
}