Load local html in WebView?

前端 未结 5 591
悲&欢浪女
悲&欢浪女 2020-11-30 03:27

I want to load a local html into a WebView WITHOUT using \"file:///\" because that does not allow cookies. Is there a way to use something like \"localhost\" ?

Secon

5条回答
  •  生来不讨喜
    2020-11-30 04:20

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            WebView view = (WebView) findViewById(R.id.webView1);
            try {
            InputStream input = getResources().openRawResource(R.raw.lights);
            Reader is = new BufferedReader(
                    new InputStreamReader(input, "windows-1252"));
    
    
                //InputStream input = getAssets().open("ws.TXT");
                int size;
                size = input.available();
                byte[] buffer = new byte[size];
                input.read(buffer);
                input.close();
                // byte buffer into a string
                javascrips = new String(buffer);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // String html = readFile(is);
    
            view.loadDataWithBaseURL("file:///android_res/raw/", javascrips, "text/html",
                    "UTF-8", null);
        }
    

提交回复
热议问题