2014-02-05 38 views
0

我已經創建了一個pdf,現在想要upload它在Google driveDropbox但不能上傳。我用下面的代碼:如何分享我的PDF與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

這應該讓你開始:https://developers.google.com/drive/android/examples/ – DaImTo

+0

我在iphone中有同樣的問題。 –

+2

特別是與文件格式「PDF」有什麼關係?它似乎只是(非常)與我切線相關。 – usr2564301

回答

0

看看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" 
}