Opening new android activity with a webview shows a blank (white) screen instead of the html content

前端 未结 11 1442
野性不改
野性不改 2020-12-29 03:29

I have been researching for 2 days and I haven\'t found a similar problem anywhere on the internet!

From the main activity, I\'m trying to open a new activity contai

11条回答
  •  孤城傲影
    2020-12-29 04:05

    I can give the another way to solve this problem. Just copy the asset file into the data path "/data/data/org.test.test/" and load it to WebView in the following way.

    String strHTMLFilePath = "file:///data/data/org.test.test/Files/help_android.html";
    webView.loadUrl(strHTMLFilePath);
    

    Use the following code to copy the HTML file from asset to data path

    void getAssetFiles() {
    
        String  WriteFileName = "/data/data/org.test.test/";
            try {
                String list[] = thisActivity.getAssets().list("Files");
                String outFileName = WriteFileName+"Files/";
                if (list != null)
                    for (int i=0; i0){
                        myOutput.write(buffer, 0, length);
                    }
                    myInput.close();
    
                    myOutput.flush();
                    myOutput.close();                           
                   }
            } catch (IOException e) {
    
            }
    
        }
    

提交回复
热议问题