2016-09-17 42 views
-1

您好我是新的android系統中我有一個存在於這個路徑的一些PDF文件無法打開asset/pdf/example.pdfPDF文件在資產文件夾中的第三方應用程序

當我嘗試PDF文件與此代碼

Intent intent = new Intent(Intent.ACTION_VIEW); 
    File file = new File("file:///android_asset/pdf/example.pdf"); 
    intent.setDataAndType(Uri.fromFile(file), "application/pdf"); 
    startActivity(intent); 

我得到這個錯誤&知道這是因爲第三方無法訪問文件 什麼是解決方案?

回答

0

知道這是因爲第三方有沒有訪問文件

file:///android_asset/僅適用於WebView AFAIK。

什麼是解決方案?

您可以使用my StreamProvider,它提供了一個ContentProvider可以從assets/服務的文件。

或者,您可以實施自己的ContentProvider,該服務可以從assets/提供該文件。或者,您可以將資產複製到本地文件(例如,getFilesDir()getCacheDir()),then use FileProvider to serve that local file

+0

老兄在提問之前我也讀過你的GITHUB項目,但不能再處理它!我新,不知道如何使用流提供程序你可以寫在我的文件路徑基礎,並給我例子? –

+0

@MohamadAmin:[StreamProvider'' demo /'project](https://github.com/commonsguy/cwac-provider/tree/master/demo)演示瞭如何從資產中提供文件等等。因此,我的許多書籍的拖放式樣本,例如[this one](https://github.com/commonsguy/cw-omnibus/tree/master/DragDrop/Legacy)(StreamProvider)用於'drag /'app模塊)。 – CommonsWare

+0

我無法處理:(嘗試兩個小時 –

相關問題