我開發的,我想顯示從資產PDF文件的應用程序顯示出來。我做了這麼多谷歌,也試過一些排列組合,但沒有工作。的Android - 閱讀PDF和使用意圖
CODE:
private void CopyReadAssets()
{
AssetManager assetManager = getActivity().getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/abc.pdf");
try
{
in = assetManager.open("abc.pdf");
out = getActivity().openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
catch (Exception e)
{
Log.e("tag", e.getMessage());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}
private void copyFile(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
}
當我點擊列表中,我稱之爲CopyReadAssets()
函數,那麼它會提示我在瀏覽器,您要打開,然後我就AdobeReader
點擊則顯示以下錯誤。
我試圖getFilesDir()...仍然是相同的錯誤 –
而我必須使用getActivity.getAssets()..因爲我在片段 –
把這兩個函數在try catch塊,讓我知道你得到哪個錯誤, –