0

I have an html string:

String htmlString = "<h1>Hello World</h1><p>DaParagraph</p>"

I want to save it as file.html to internal/external storage and then read it. What should I do?

Vassily
  • 5,263
  • 4
  • 33
  • 63
  • http://stackoverflow.com/questions/11289949/how-to-save-parsed-text-file-in-internal-external-storage-in-android – J.K Sep 04 '15 at 06:30

2 Answers2

2

Alternative easy option.

You should store that htmlstring to either SQLite database or SharedPreference as string.

and load that string as html in webview

String htmlString = "<h1>Hello World</h1><p>DaParagraph</p>";
                webview.getSettings().setJavaScriptEnabled(true);
                webview.loadDataWithBaseURL("", htmlString, "text/html", "UTF-8","");
Jaykumar Donga
  • 380
  • 1
  • 3
  • 18
1

1. Please save your html which is string response from server in shared preferences like this :

SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("HTML", "your html string");
        editor.commit();  

2. Get this String wherever you want to use :

SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(context); 
String htmlString=preferences.getString("HTML", null);

3. Convert String to html :

Html.fromHtml((String) htmlString).toString();

Happy Coding.!!

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66