0

I have downloaded 2 files (1 HTML file and 1 image) from server in Environment.DIRECTORY_DOWNLOADS. Now i am trying to load the HTML file (with image) saved in Environment.DIRECTORY_DOWNLOADS in webview. But nothing is loaded.

What's the problem?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = (WebView) findViewById(R.id.webView);
    button = (Button) findViewById(R.id.button);

    File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    File htmlFile = new File(file.getAbsolutePath()+"/test.html");
    webView.loadUrl(htmlFile.getAbsolutePath());
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                myDownload("http://xxxxxx.com/xxxx/test.html");
                myDownload("http://xxxxxx.com/xxxx/mypic1.jpg");
            } catch (Exception e) {
                Toast.makeText(MainActivity.this, e.getMessage() + "\n" + e.getCause(), Toast.LENGTH_LONG).show();
            }
            //
        }
    });
}
manfcas
  • 1,933
  • 7
  • 28
  • 47
akkk
  • 1,457
  • 4
  • 23
  • 41
  • 1
    You have asked that before. Yesterday. http://stackoverflow.com/questions/38600247/webview-not-loading-the-file-from-internal-storage But you even did not answer my questings or comments. Or answers and comments of others. You are supposed to do so and not run away silently of your post. – greenapps Jul 27 '16 at 22:06
  • @greenapps Here the problem is bit different. Sorry for that. I have replied them now :) – akkk Jul 28 '16 at 12:33
  • Then what is different? Is it relevant that those files are download from a server? Dont think si. They should just be in the indicated path. So add `if ( !htmlFi.exists()) { toast sorry this file does not exist; } else`. Please report. – greenapps Jul 28 '16 at 14:10
  • And add the "file://" for .loadUrl(). – greenapps Jul 28 '16 at 14:25

0 Answers0