1.
package tuo.test.activity; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.Window; import android.webkit.JsResult; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.widget.Toast; public class Browser extends Activity { private static final String TAG = "Browser"; private WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.getWindow().requestFeature(Window.FEATURE_PROGRESS); this.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); setContentView(R.layout.browser); loadHtml(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { webView.goBack(); return true; } return super.onKeyDown(keyCode, event); } private void loadHtml() { String action = getIntent().getStringExtra("action"); String html = "file:///android_asset/html/person.html?action=" + action; webView = (WebView) findViewById(R.id.web_view); webView.getSettings().setJavaScriptEnabled(true); webView.addJavascriptInterface(this, "android"); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { // TODO Auto-generated method stub Toast.makeText(Browser.this, message, 3000).show(); result.confirm(); return true; // I handled it } public void onProgressChanged(WebView view, int newProgress) { // TODO Auto-generated method stub // super.onProgressChanged(view, newProgress); setTitle("loading..."); setProgress(newProgress * 100); if (newProgress == 100) { setTitle(""); } } }); webView.loadUrl(html); } public String getHISAccount() { return "00000"; } }