0

I want to open remotly and offline a pdf file in an android webview which it locate on my NAS in my Home LAN.

I tried this but i had a network error in the webview (Web page not available) :

enter image description here

public void OpenPDF(String Path) {
  try {
    WebView webView=new WebView(ListDir.this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.setWebViewClient(new Callback());
    Log.i("",""+"file://"+Path);
    webView.loadUrl("file:///"+Path);
    setContentView(webView);
 }
 catch(Exception e) {
   Toast(""+e);
 }
}
private class Callback extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(
            WebView view, String url) {
        return(false);
    }
}
where Path = 192.168.0.254/Disque dur/AffichePDF.pdf 

The Log.i = 07-23 15:15:43.523: I/(7988): file:///192.168.0.254/Disque dur/AffichePDF.pdf

Chrome android tells ERR : 10 ERR_ACCESS_DENIED on my s3 and Network error on default browser. Does any configuration should be done on the device to use file:/// ?

The path file:///192.168.0.254/Disque dur/AffichePDF.pdf works fine on my PC and i can navigate and list files on my NAS from my app.

Somebody knows a tip to do that working ?

Thanks

Wildchild7
  • 347
  • 2
  • 6
  • 13

1 Answers1

1

I think you're confusing things. Your PC browser has a plugin that allows rendering PDF files, this is why you can see the PDF file directly on the browser. Your Android browser most likely does not have this feature, because this is very memory consuming and not suited to mobile devices. So no, you can't do this unless you have a browser that supports plugins for rendering PDF files. If your browser supports PDF files, then it will show it straight ahead. If not, you'll have to download it (like the good ol' times when PC browsers did not have the PDF plugin) and then display it with a PDF reader.

You might be interested in this and this

Community
  • 1
  • 1
m0skit0
  • 25,268
  • 11
  • 79
  • 127
  • hummm..ok I see it's the native web browser on my android x86 VM. I installed adobe reader but no plugin for web browser. But why can't i use the file tree with file:/// command ?? My VM App has INTERNET permissions and the VM networks is OK – Wildchild7 Jul 23 '13 at 14:02
  • Doesn't matter if VM or real device, Android works the same way. About file:/// It's probable that Android browser does not recognize file:// URLs. In my device (4.1) it does work with default browser. What Android version are you using? – m0skit0 Jul 23 '13 at 14:08
  • It's a 4.0.4 version but with ma real Samsung S3 on 4.1.2 i've the same problem + an ERR_ACCESS_DENIED on the web page... should be an access problem from my Box/NAS.. – Wildchild7 Jul 23 '13 at 16:01
  • Can you access local filesystem in the browser? Try `file://mnt/` for example. – m0skit0 Jul 23 '13 at 16:56
  • Hi, no same result on both virtual and real device. – Wildchild7 Jul 24 '13 at 07:52
  • Chrome android tells ERR : 10 ERR_ACCESS_DENIED on my s3 and Network error on default browser. Does any configuration should be done on the device to use file:/// ? – Wildchild7 Jul 24 '13 at 08:02
  • Cannot give network error, this is local access. It's file:// not file:///. – m0skit0 Jul 24 '13 at 08:23
  • Both command should works. I think fille is not accepted in my case. strange – Wildchild7 Jul 24 '13 at 08:35
  • sorry, you're right i misssed the "sdcard". With the correct Path i've a blank web page but no error. So it meens that android can't find the network path file://192.168.0.254/ ? – Wildchild7 Jul 24 '13 at 09:40
  • Blank is OK. This means directory is empty. Also using `file` in the URI [means local file](http://en.wikipedia.org/wiki/File_URI_scheme). `file://192.168.0.254/` has no meaning because you don't have any folder called `192.168.0.254`. If you want to access host with IP 192.168.0.254, you first need to start a server in that machine. What server you have? – m0skit0 Jul 24 '13 at 09:43
  • 192.168.0.254 is my home NAS. For my dev i'm using a wamp server – Wildchild7 Jul 24 '13 at 09:52
  • I don't know what is WAMP or NAS. This WAMP server, what protocol does it use? HTTP? What port is it configured to listen? – m0skit0 Jul 24 '13 at 10:07