How to access SDCARD using Javascript LocalFileSystem in WebView in android ..?
I want to send a list of directories in my android web browser by clicking a button in webview only.
WebView started Fine and it is listening for events, but I get an exception
Uncaught ReferenceError: LocalFileSystem is not defined at file:///android_asset/FirstFile.html:11
Here is the complete code
Activity:
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);
}
}
Here is 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>
Please provide me with a suitable solution
+3
source to share