V
V
Vladislav2015-10-29 20:41:38
Android
Vladislav, 2015-10-29 20:41:38

How does loadDataWithBaseURL work?

There is an assets folder, it contains a screen.png picture and a MainActiviy with the following code:

package webviewtest.webviewtest;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    WebView view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        view = (WebView) findViewById(R.id.webView);
        String data = "<html><body><img src=\"screen.png\" style=\"display:block;margin-left:auto;margin-right:auto;position:relative;top:50%;margin-top:-101px;\"></body></html>";
        view.loadDataWithBaseURL("file:///android_asset/", data, "text/html", "utf-8", null);
        view.setWebViewClient(new WebViewClient());
    }
}

This code works great, the problem is that I have a folder called assetS and in loadDataWithBaseURL I pass file:///android_asset/ but if I write android_assetS, then nothing works, why is that? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2015-10-30
@MrBikus

In short, the folder is called assets, and file:///android_asset/ is just a pointer to it, which is defined in the URLUtil class. It doesn't matter if we write /, assuming that / is assets.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question