tags:

views:

26

answers:

1

I was trying to display a static html page in an android app having some images in it. I saved the image in assests folder and also in res/raw folder. I was loading html file with this technique and html file is also in res/raw folder.

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);

    String data = ResourceUtils.loadResToString(R.raw.temp, this);

    final String mimetype = "text/html";
    final String encoding = "UTF-8";
    mWebView.loadData(data, mimetype, encoding);

I tried different ways to refer to image like.

  1. img1.png, /img1.png, file:///img1.png, content://img1.png

  2. HtmlViewer/assets/img1.png, content:///HtmlViewer/assets/img1.png and file:///HtmlViewer/assets/img1.png

  3. PackageName/assets/img1.png, content:///PackageName/assets/img1.png and file:///PackageName/assets/img1.png

Can anyone tell me how to get path for image?

+1  A: 

file:///android_asset/file_name.ext

This should work. Use this method instead. loadDataWithBaseURL("file:///android_asset/", summary, "text/html", "utf-8", null);

Kumar Bibek
Sweet! Thanks indeed!
Wajih