Reputation: 469
I'm trying to load a html file from sd-card. Note: -> if i load http://www.google.com it works. -> the file exists -> i have permissions for internet and WRITE_EXTERNAL_STORAGE
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addB = (Button) findViewById(R.id.add);
webComp = (WebView) findViewById(R.id.webC);
WebSettings webSettings = webComp.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
webSettings.setAllowFileAccess(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webComp.setWebViewClient(new HelloWebViewClient());
webComp.loadUrl("/sdcard/FMS/1/message.html");
}
Thank you ! :)
Upvotes: 17
Views: 14774
Reputation: 4901
You can access it like this, any files local to the .html file will be able to be loaded except for video
webView.loadUrl("file://" + Environment.getExternalStorageDirectory() + "/myapprepository/index.html");
Upvotes: 0
Reputation: 33509
Misca,
You shouldn't hard code the directory of the sdcard like that. Its typically at /mnt/sdcard/
but this is never assured. You should also always check if the sdcard exists and is mounted first!
You want to use the following:
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d(TAG, "No SDCARD");
} else {
webComp.loadUrl("file://"+Environment.getExternalStorageDirectory()+"/FMS/1/message.html");
}
Upvotes: 39