1

我想從一些應用程序(例如谷歌驅動器,Dropbox)分享pdf,doc文件到我的android應用程序。如何共享.pdf,.doc文件到我的應用程序

我試過

我可以分享一個圖像到使用這些代碼片段我的申請,我可以得到AndroidManifest.xml使用下面的代碼映像路徑。

<intent-filter> 
      <action android:name="android.intent.action.SEND" /> 



       <data android:mimeType="image/*" /> 


      <category android:name="android.intent.category.DEFAULT" /> 


      </intent-filter> 

在我的活動使用上面的代碼,我可以得到共享映像路徑,這樣我可以執行

Intent myintent = getIntent(); 
      Bundle extras = myintent.getExtras(); 
      String action = myintent.getAction(); 

      // if this is from the share menu 
      if (Intent.ACTION_SEND.equals(action)) { if (extras.containsKey(Intent.EXTRA_STREAM)) { 
      // Get resource path 
      Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); 
      String filename = parseUriToFilename(uri); 

      if (filename != null) { 


       doing some process here// 

      } 
      } 
      } 

public String parseUriToFilename(Uri uri) { 
      String selectedImagePath = null; 
      String filemanagerPath = uri.getPath(); 

      String[] projection = { MediaStore.Images.Media.DATA }; 
      Cursor cursor = getContentResolver().query(uri, projection, null, null, null); 

      if (cursor != null) { 
      // Here you will get a null pointer if cursor is null 
      // This can be if you used OI file manager for picking the media 
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
      cursor.moveToFirst(); 
      selectedImagePath = cursor.getString(column_index); 
      } 

      if (selectedImagePath != null) { 
      return selectedImagePath; 
      } 
      else if (filemanagerPath != null) { 
      return filemanagerPath; 
      } 
     return null; 
      } 

什麼,我真的需要

我task.I想共享.pdf,.doc文件到我的應用程序爲此目的我需要file.so的確切位置如果我將這些文件共享到我的應用程序中,如何獲得pdf,doc文件路徑。

回答

0

使用上面的代碼,我可以得到共享映像路徑,這樣我可以完成我的任務

沒有,你可以得到的路徑一些圖像,那些發生在由MediaStore索引。並非所有圖像都由MediaStore索引。並非所有圖像都存儲在應用可以訪問的路徑中的文件中。

更一般地,not every content://Uri that you will find will be represented by a file that you can access。相反,您需要使用適當的ContentResolver方法來使用內容,例如openInputStream()

我想和大家分享.PDF,.DOC文件到我的應用程序爲目的,我需要的文件

對於那些碰巧也MediaStore索引的文件的確切位置,你是歡迎嘗試使用與MediaStore索引的圖像相同的解決方案。

+0

我怎樣才能得到pdf文件的路徑。?你可以提供任何示例代碼來獲取文件路徑。 – Jamal

相關問題