【发布时间】:2014-01-30 17:45:11
【问题描述】:
我正在开发一个应用程序,我想显示资产中的 pdf 文件。我做了很多谷歌,也尝试了排列和组合的数量,但没有奏效。
代码:
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 然后它显示以下错误。
【问题讨论】:
标签: android pdf android-intent