0
        webView.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///android_asset/content/{0}", WebUtility.UrlEncode("program.pdf"))));

Does someone know the equivalent of that code?

I tried

webView.loadUrl(String.format("file:///android_asset/pdfjs/web/viewer.html?file={0}", String.format("file:///android_asset/content/{0}", URLEncoder.encode("program.pdf","utf-8"))));

But i guess it's wrong because it is not doing what it's supposed to do

Sakura Fukuyoshi
  • 1,461
  • 1
  • 10
  • 14

1 Answers1

0

In Java, String.format would use %s for string values in place of those {0} values

Its not really clear what benefits you get from URL encoding program.pdf since it's already a valid URL format for a filename, so it's not necessary, but I'll assume that's just an example.

So you're probably looking for

String filename = "program.pdf";
String url = String.format("file:///android_asset/pdfjs/web/viewer.html?file=file:///android_asset/content/%s", URLEncoder.encode(filename ,"utf-8"));
// TODO: print the url here 
webView.loadUrl(url);
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Thanks for that. Now it doesn't show the missing pdf error but it doesn't show my pdf. I don't know if it is because of this URLEncoder.encode("program.pdf","utf-8") – Sakura Fukuyoshi Aug 17 '18 at 04:42
  • I've not used this PDF.js library before, so I'm not sure how it works. But I would try using some proper native library. For example https://stackoverflow.com/a/51001474/2308683 – OneCricketeer Aug 17 '18 at 04:48