我想仅通过单击 webview 中的按钮来显示我的 Android webview 中的目录列表。
webView 启动正常,它正在监听事件,但我遇到了异常
Uncaught ReferenceError: LocalFileSystem is not defined at file:///android_asset/FirstFile.html:11
这是完整的代码
活动:
public class Home extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("file:///android_asset/FirstFile.html");
setContentView(webview);
}
}
这是 FirstFile.xml
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript" charset="utf-8">
function getFileSystem() {
window.requestFileSystem = window.requestFileSystem
||
window.requestFileSystem(LocalFileSystem.PERSISTENT, 1024 * 1024,
onFileSystemSuccessUpload, fail);
window.resolveLocalFileSystemURL("file:///mnt/sdcard",
onResolveSuccess, fail);
document.getElementById("text1").innerHTML = "Hii its done";
}
function onResolveSuccess(fileEntry) {
document.write("URI Resolved");
}
function fail() {
console.log("Error getting system")
}
function successReader(entries) {
var i;
for (i = 0; i < entries.length; i++) {
alert(entries[i].name);
if (entries[i].isDirectory == true) {
var directoryReaderIn = entries[i].createReader();
directoryReaderIn.readEntries(successReader, fail);
}
}
}
</script>
<input type="text" id="text1">
<button onclick="getFileSystem()">Click Me !!</button>
</body>
</html>
请给我一个合适的解决方案