How to open . html files in my application?

Asked

Viewed 2,077 times

-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.

  • I just want to view the offline . html within the same APP

  • For example, there is a file called ".html file" on the SD card, I want to view it in web page form

  • A specific one that is on the SD card

  • 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.

1 answer

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

You are not signed in. Login or sign up in order to post.