正如巴拉克所说,您可以将其从资产中复制到内部存储或SD卡中,然后使用内置的pdf应用程序从中打开它。
关注Snippet将为您提供帮助。(我已经更新了此代码,以写入内部存储并从中读取文件。
但是我不推荐这种方法,因为pdf文件的大小可以超过100mb。
因此不建议将大文件保存到内部存储中
还要确保在将文件保存到您使用的内部存储时
openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
然后,只有其他应用程序才能读取它。
检查以下代码段。
package org.sample;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.content.res.AssetManager;import android.net.Uri;import android.os.Bundle;import android.util.Log;public class SampleActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); CopyReadAssets(); } private void CopyReadAssets() { AssetManager assetManager = getAssets(); InputStream in = null; OutputStream out = null; File file = new File(getFilesDir(), "git.pdf"); try { in = assetManager.open("git.pdf"); out = 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.parse("file://" + getFilesDir() + "/git.pdf"), "application/pdf"); 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); } }}确保包括
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在清单中



