0

我已经从服务器下载 2 个文件(1 个 HTML 文件和 1 个图像)Environment.DIRECTORY_DOWNLOADS。现在我正在尝试加载保存Environment.DIRECTORY_DOWNLOADS在 webview 中的 HTML 文件(带图像)。但是什么都没有加载。

有什么问题?

@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();
            }
            //
        }
    });
}
4

0 回答 0