3

I load html files from remote server and show them in webview but default font face for my language is a bit messy so I tried to load fonts from asset folder. here are my java code and html file.

webView.getSettings().setAppCacheEnabled(false);
webView.getSettings().setAppCacheMaxSize(1);
webView.getSettings().setDomStorageEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
webView.setWebViewClient(new MyWebViewClient());
isShowing=true;
dialog.show();
String address="http://server/test.html";
Log.d("checking", address);
webView.loadUrl(address);

html code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title> Title Here </title>

    <style type="text/css">
    @font-face {
      font-family:nazanin;
      src:url('file:///android_asset/fonts/BNAZANIN.TTF');
    }

    body {
      font-family: nazanin;
      font-size: medium;
      text-align: justify;
    }

</style>

</head>

<body>

  <p>this is for test</p>

</body>
</html>

the problem is after loading I got this error:

11-21 10:50:55.439: E/Web Console(9572): Not allowed to load local resource: file:///android_asset/fonts/BNAZANIN.TTF at :0

what is the solution for this?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Mohamad Ghafourian
  • 1,052
  • 1
  • 14
  • 26
  • This question is wrongly marked as a duplicated, OP wanted to access to a font, from a webview of an external url, not to read a webview with a local .html file as redirected... way to go community... – desgraci Mar 07 '16 at 15:34

1 Answers1

0

I end up adding that font on server and link to that in html file. I tried almost any ways and I think this is the only way that works. LoadDataWithBaseUrl and adding font in asset folder is not the way when you have external files like css and js to use in html.

Mohamad Ghafourian
  • 1,052
  • 1
  • 14
  • 26