Android   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 使用PDFViewer.jar从assets文件夹中读取pdf大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我想使用PDFViewer.jar阅读存储在asset文件夹中的pdf文件,

我试过这种方式,但我收到错误消息,不幸的是它停止了.

谁能帮助我如何实现它.

public class MainActivity extends Activity {

@Override
protected 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.access$600(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 Activit
y 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所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: