-2
I’m making an application for Android and wanted to know how to open and display a file .html
specific located on SD card directly in my application.
-2
I’m making an application for Android and wanted to know how to open and display a file .html
specific located on SD card directly in my application.
3
It will depend a lot on where the file is, being a specific location, first add a webView
to your app, in case here the name webView1
, if you use another ID for your webView you should change in the examples below the webView1
by the ID you are using.
Then you’ll need class Environment:
The code should look something like:
WebView meuWebView = (WebView) findViewById(R.id.webView1);
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d("Teste html no SD", "sem cartão SD");
} else {
String path = Environment.getExternalStorageDirectory();
//Esta linha é apenas para teste
Log.d("Teste html no SD", "file://" + path + "/pasta/arquivo.html");
meuWebView.loadUrl("file://" + path + "/pasta/arquivo.html");
}
I don’t have the ADT installed then I could not test, but if the above example does not work and the way "file://" + path + "/pasta/arquivo.html"
is wrong (depending on the Log.d
), then try this:
WebView meuWebView = (WebView) findViewById(R.id.webView1);
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d("Teste html no SD", "sem cartão SD");
} else {
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
//Esta linha é apenas para teste
Log.d("Teste html no SD", "file://" + path + "/pasta/arquivo.html");
meuWebView.loadUrl("file://" + path + "/pasta/arquivo.html");
}
Thank you for the reply!!
Browser other questions tagged java android
You are not signed in. Login or sign up in order to post.
I just want to view the offline . html within the same APP
– Drkill32
For example, there is a file called ".html file" on the SD card, I want to view it in web page form
– Drkill32
A specific one that is on the SD card
– Drkill32
I edited the Drkill32 question as per your comments, if you disagree with something edit again and explain what you really want, I posted an answer, try it.
– Guilherme Nascimento