I am trying to open local html file in my Android application.
The file is located under my assets folder. So I am setting a WebViewClient and loading my page into i
Download source code from here (Open html file from assets android)
MainActivity.java
package com.deepshikha.htmlfromassets;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
WebView webview;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init(){
webview = (WebView)findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/download.html");
webview.requestFocus();
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading");
progressDialog.setCancelable(false);
progressDialog.show();
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
try {
progressDialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Thanks!