我正在处理需要在Web视图中显示一些信息的项目,但是需要通过组合存储在内部存储上的两个或多个文件(html/text)
来动态生成文件,我能够组合文件但不能能够在webview
中呈现它。请指导......
这是代码
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());
}
}
答案 0 :(得分:0)
我已经把它弄清楚....已保存的文件存储并使用了webViewBasic.loadUrl(" file:///" + file.getAbsolutePath());