我想使用pdfVIEwer.jar阅读存储在asset文件夹中的pdf文件,
我试过这种方式,但我收到错误消息,不幸的是它停止了.
谁能帮助我如何实现它.
public class MainActivity extends Activity {@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); copyReadAssets();}private voID copyReadAssets() { AssetManager assetManager = getAssets(); inputStream in = null; OutputStream out = null; file file = new file(getfilesDir(), "ABC.pdf"); try { in = assetManager.open("ABC.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() + "/ABC.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); }}}
logcat详细信息:
02-05 11:09:05.896: E/AndroIDRuntime(6516): FATAL EXCEPTION: main 02-05 11:09:05.896: E/AndroIDRuntime(6516): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.syntel.pdfreader/com.syntel.pdfreader.MainActivity}: androID.content.ActivityNotFoundException: No Activity found to handle Intent { act=androID.intent.action.VIEW dat=file:///data/data/com.syntel.pdfreader/files/ABC.pdf typ=application/pdf } 02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2180) 02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.app.ActivityThread.access0(ActivityThread.java:141) 02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.os.Handler.dispatchMessage(Handler.java:99) 02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.os.Looper.loop(Looper.java:137)02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.app.ActivityThread.main(ActivityThread.java:5041)02-05 11:09:05.896: E/AndroIDRuntime(6516): at java.lang.reflect.Method.invokeNative(Native Method)02-05 11:09:05.896: E/AndroIDRuntime(6516): at java.lang.reflect.Method.invoke(Method.java:511)02-05 11:09:05.896: E/AndroIDRuntime(6516): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 02-05 11:09:05.896: E/AndroIDRuntime(6516): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:560) 02-05 11:09:05.896: E/AndroIDRuntime(6516): at dalvik.system.NativeStart.main(Native Method) 02-05 11:09:05.896: E/AndroIDRuntime(6516): Caused by: androID.content.ActivityNotFoundException: No Activity found to handle Intent { act=androID.intent.action.VIEW dat=file:///data/data/com.syntel.pdfreader/files/ABC.pdf typ=application/pdf }02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)02-05 11:09:05.896: E/AndroIDRuntime(6516): at androID.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
解决方法:
我用这个Android-Pdf-Viewer-Library创建了我的现场演示
你可以下载我的Demo with Library
总结以上是内存溢出为你收集整理的android – 使用PDFViewer.jar从assets文件夹中读取pdf全部内容,希望文章能够帮你解决android – 使用PDFViewer.jar从assets文件夹中读取pdf所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)