Reputation: 347
I need to display a PDF file located in my app dir in a webwiev without using Google Docs.
This is my code for the webview:
public void OpenPDF() {
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file://mnt/data/data/com.example.android/files/Docs/test.pdf");;
}
I get a blank webview instead of below code works
public void OpenPDF() {
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file://mnt/data/data/com.example.android/files/Docs/test.html");
}
I tested directly in my web browser with file://mnt/data/data/com.example.android/files/Docs/test.pdf
and test.html
and it worked for both. I installed a PDF reader.
07-25 17:09:07.967: W/webcore(11347): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1683)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore$EventHub.access$7900(WebViewCore.java:926)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1795)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebView.sendOurVisibleRect(WebView.java:2917)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:593)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:984)
07-25 17:09:07.967: W/webcore(11347): at android.os.Handler.handleCallback(Handler.java:605)
07-25 17:09:07.967: W/webcore(11347): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 17:09:07.967: W/webcore(11347): at android.os.Looper.loop(Looper.java:137)
07-25 17:09:07.967: W/webcore(11347): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-25 17:09:07.967: W/webcore(11347): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 17:09:07.967: W/webcore(11347): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 17:09:07.967: W/webcore(11347): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-25 17:09:07.967: W/webcore(11347): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-25 17:09:07.967: W/webcore(11347): at dalvik.system.NativeStart.main(Native Method)
Any ideas about why only pdf files won't open ?
Upvotes: 2
Views: 10492
Reputation: 2424
Their seems to be an answer to your question already in stack overflow at Open Local Html File in Webview - Android
to sum it up : Usage of file:/// before your actual path should solve your problem for everything except .pdf files
Webview does not support PDF in android :(. You need to use google doc according to different sources.
Upvotes: 3
Reputation: 23
I think you should try with 3 slashes, like that:
webview.loadUrl("file:///mnt/data/data/com.example.android/files/Docs/test.pdf");
Upvotes: -1