2015-04-22 50 views
0

我想打開本地的PDF文件,通過共享意向預安裝PDF查看器是這樣的:顯示本地PDF文件與外部應用程序

Uri uri= Uri.parse("file:///android_asset/manual.pdf"); 
Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
intent.setType("application/pdf"); 
startActivity(intent); 

該應用程序選取器所示,當我點擊Adobe PDF,但沒有顯示PDF文件。

我做錯了什麼,還是根本不可能?

+0

,你必須不停的PDF文件。它是否在資產?你傳遞的路徑是錯誤的。它無法從該路徑打開文件。 – Raghavendra

+0

是的,我的文件位於資產文件夾 - 當我檢查uri時,它看起來很好。 – deimos1988

+0

按照此鏈接http://stackoverflow.com/questions/17085574/read-a-pdf-file-from-assets-folder從資產中打開pdf。 – Raghavendra

回答

0

這爲我工作,

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/directory/"+theNamesOfFiles)),"application/pdf"); 
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
startActivity(intent); 
相關問題