所以有一段时间以来我一直在尝试实施joanzapata的pdfview,来自: " http://joanzapata.com/android-pdfview/"
主要关注的是API-10 +友好。
无论我做什么,我都会得到一个或另一个错误,不知怎的,现在我让项目工作(显然)但是当我找到我的PDF文件并尝试使用与项目Sample相同的代码加载它时,我得到了以下问题。
首先是我的代码:
...
//File currentLoc = new File(string_pdfLoc);
...
//File thePdf = currentLoc;
//thePdf is of type File
if( thePdf != null ) {
Log.d("MyDebug", "1/3 File not Null");
if( thePdf.exists() ) {
Log.d("MyDebug", "2/3 File exists");
if (thePdf.canRead()) {
Log.d("MyDebug", "3/3 File can be Read");
Log.d("MyDebug", "thePDF: " + thePdf.getAbsolutePath());
//------ PDF should Exist ----------------------
Log.d("MyDebug","Should now load thePDFView");
//pdfView.fromAsset(pdfName)
Log.d("MyDebug","thePDFView.fromAsset");
thePDFView.fromAsset(thePdf.getAbsolutePath() );
Log.d("MyDebug","thePDFView.fromAsset.load");
thePDFView.fromAsset(thePdf.getAbsolutePath() ).load();
} else {
Log.d("MyDebug", "File exists, but cannot Read");
}
}else{
Log.d("MyDebug", "File != null, but !exists");
}
}else{
Log.d("MyDebug","thePDF, is still null");
}
现在出现错误,请注意"公司" &安培; "的projectname"通常命名不同,但仍然是小写的字符,但我隐藏了他们的名字。
Found a PDF File
D/MyDebug? 1/3 File not Null
D/MyDebug? 2/3 File exists
D/MyDebug? 3/3 File can be Read
D/MyDebug? thePDF: /storage/emulated/0/Android/data/com.projectname.company.projectname/files/ThisisaPDF.pdf
D/MyDebug? Should now load thePDFView
D/MyDebug? thePDFView.fromAsset
D/AndroidRuntime? Shutting down VM
W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x41942da0)
E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.projectname.company.projectname, PID: 9591
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.projectname.tpub.projectname/com.projectname.company.projectname.PdfViewActivity}: com.joanzapata.pdfview.exception.FileNotFoundException: /storage/emulated/0/Android/data/com.projectname.company.projectname/files/ThisisaPDF.pdf does not exist.
...
Caused by: com.joanzapata.pdfview.exception.FileNotFoundException: /storage/emulated/0/Android/data/com.projectname.company.projectname/files/ThisisaPDF.pdf does not exist.
at com.joanzapata.pdfview.PDFView.fromAsset(PDFView.java:905)
at com.projectname.company.projectname.PdfViewActivity.onCreate(PdfViewActivity.java:88)
以下是我在Manifest中的权限:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
这是我的Gradle(app).Build文件:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.joanzapata.pdfview:android-pdfview:1.0.+@aar'
}
据我所知,插件应该被引入,否则我会期待一些错误,例如我过去对Gradle的错误。
我们非常欢迎任何建议,我会经常检查这些建议,我可以轻易地尝试和回应任何建议。