2017-07-19 45 views
0

我希望我的應用能夠打開外部PDF,因此實現了此意圖過濾器,它允許我在選擇PDF時打開我的應用。Android「open with ...」給出了不同的URL(意圖過濾器)

 <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <data android:mimeType="application/pdf" /> 
     </intent-filter> 

在某些設備中的數據的URL是這樣的:

content://downloads/all_downloads/4860 

,我可以用這段代碼打開:

Cursor returnCursor = this.cordova.getActivity().getApplicationContext().getContentResolver().query(returnUri, null, null, null, null); 

在像一加一的其它裝置(可以真的不知道Android版本有什麼區別)意圖收到了這個URL:

file:///storage/emulated/0/Download/pdf-test.pdf 

我無法打開此URL,因爲我可能無法訪問它。任何人都知道我做錯了什麼?

回答

0

好的,這畢竟容易。必須請求讀/寫外部存儲的權限,以便我可以處理文件的URL。