1. Download our Official Android App: Forums for Android!

Support Combine text/html file and render in webview

Discussion in 'Android Apps & Games' started by chandutayade22389, Sep 11, 2017.

  1. chandutayade22389

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Aug 18, 2017

    Aug 18, 2017
    5
    0
    5
    Male
    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()); } }
     

    Advertisement

    #1 chandutayade22389, Sep 11, 2017
    Last edited: Sep 11, 2017
  2. chandutayade22389

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Aug 18, 2017

    Aug 18, 2017
    5
    0
    5
    Male
    I had figured it out.... saved file in storage and used webViewBasic.loadUrl("file:///" + file.getAbsolutePath());
     

Share This Page

Loading...