android Not allowed to load local resource:file:///android_asset

前端 未结 5 1906
别那么骄傲
别那么骄傲 2020-12-10 12:22

I\'m trying to load an html page from a server the page contains a script that links to android sdcard .js file.

Java:

String url =\"http://192.168.8         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 13:00

     String htmlStr="..your html data in string..\"data/replace.js\" ";
     if (htmlStr.contains("\"data/replace.js\"")) {
         String html = data.replace("\"data/replace.js\"", "\"file:///storage/emulated/0/documents/HtmlContent/new_replace.js\"");
         ((Activity) mContext).runOnUiThread(() -> {
                loadDataWithBaseURL("file:///storage/emulated/0/documents/HtmlContent/", html, "text/html", "UTF-8", "");
          });
      }
    

    Try following code to load Html content from sdcard.

     String fileName = "something.html";
     File lFile = new File(Environment.getExternalStorageDirectory() + fileName);
     webview.loadUrl("file:///" + lFile.getAbsolutePath());
    

提交回复
热议问题