I am making an application in which i want to open a local html page in the browser. I am able to open google.com. But when i\'m opening local html file. But i am getting fo
To save the html string as file:
public File saveStringToHtmlFile(String htmlString) {
File htmlFile = null;
try {
// If the file does not exists, it is created.
htmlFile = new File((ContextUtils.getAppContext()).getExternalFilesDir(null), "HTML_FILE_NAME.html");
if (!htmlFile.exists()) {
htmlFile.createNewFile();
}
// Adds a line to the file
BufferedWriter writer = new BufferedWriter(new FileWriter(htmlFile, false));
writer.write(htmlString);
writer.close();
} catch (IOException e) {
Log.e(TAG, "Unable to write to HTML_FILE_NAME.html file.");
}
return htmlFile;
}
To open the html file with browser:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(htmlFile), "text/html");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);