【问题标题】:How can i share my pdf with dropbox and Google drive?如何与 Dropbox 和 Google Drive 共享我的 pdf?
【发布时间】:2014-02-05 13:04:48
【问题描述】:

我创建了一个pdf,现在想在Google drive 和Dropbox 上upload,但无法上传。我使用了以下代码:

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

【问题讨论】:

  • 这应该可以帮助您入门:developers.google.com/drive/android/examples
  • 我在 iphone 中遇到了同样的问题。
  • 这与文件格式“PDF”有什么关系吗?它似乎只(非常)与我无关。
  • @RanjanSahu,那么你应该发布另一个关于它的问题(当然,在做一些研究之后),因为代码不会一样......

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


【解决方案1】:

看看user2459928的这里的答案:Android Launch a Google Drive application from another application not uploaded file

此外,我强烈建议将 startActivity() 包装在 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"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多