- Forum posts: 3
Sep 11, 2017, 4:29:29 PM via Website
Sep 11, 2017 4:29:29 PM via Website
I am working on project which need to display some information in web view, but the file is needed to be generated dynamically by combining two or more file (html/text) stored on internal storage, i am able combine files but not able to render it in webview. Please guide......
String html= CheckLocalHtml(context,"FileName.html");
webViewBasic.loadDataWithBaseURL("file:///",html,"text/html", "utf-8", null);
public String CheckLocalHtml(Context context, String fName) { try { String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).toString(); File mFile, mDir; mDir = new File(root); if (mDir.exists()) { mFile = new File(mDir, fName); if (mFile.exists()) { StringBuilder contentBuilder = new StringBuilder(); BufferedReader in = new BufferedReader(new FileReader(mFile)); String s=""; while ((s = in.readLine()) != null) { contentBuilder.append(s); } in.close(); return contentBuilder.toString(); } else { Toast.makeText(context, "Page not found", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(context, "Directory not found", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { Log.e("ReadHTML","Error="+e.toString()); } }
— modified on Sep 11, 2017, 4:57:26 PM