如何与Dropbox和Google云端硬盘分享我的pdf?

时间:2014-02-05 13:04:49

标签: android pdf share dropbox google-drive-api

我创建了一个pdf,现在希望在uploadGoogle driveDropbox,但无法上传。我使用了以下代码:

    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);

1 个答案:

答案 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"
}
相关问题