WEB开发网
开发学院手机开发Android 开发 Android 之 webView 加载 javascropt 阅读

Android 之 webView 加载 javascropt

 2010-04-14 18:02:00 来源:WEB开发网   
核心提示:53. // TODO Auto-generated method stub54. Log.d("aa", message);55. Log.d("url", url);56. Log.d("result", ""+result);57.5

53. // TODO Auto-generated method stub

54. Log.d("aa", message);

55. Log.d("url", url);

56. Log.d("result", ""+result);

57.

58. result.confirm();

59. return super.onJsAlert(view, url, message, result);

60.

61. }

62.

63.

64. }

public class webJsDemo extends Activity {

/** Called when the activity is first created. */

private WebView mWebView;

private Handler mHandler = new Handler();

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

mWebView = (WebView) findViewById(R.id.wv1);

WebSettings webSettings = mWebView.getSettings();

webSettings.setSavePassword(false);

webSettings.setSaveFormData(false);

webSettings.setJavaScriptEnabled(true);

webSettings.setSupportZoom(false);

mWebView.setWebChromeClient(new MyWebChromeClient());

mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");

mWebView.loadUrl("file:///android_asset/demo.html");

}

final class DemoJavaScriptInterface {

DemoJavaScriptInterface() {

}

/**

* This is not called on the UI thread. Post a runnable to invoke

* loadUrl on the UI thread.

*/

public void clickOnAndroid() {

mHandler.post(new Runnable() {

public void run() {

mWebView.loadUrl("javascript:wave()");

}

});

}

}

/**

* Provides a hook for calling "alert" from javascript. Useful for

* debugging your javascript.

*/

final class MyWebChromeClient extends WebChromeClient {

@Override

上一页  1 2 3 4 5  下一页

Tags:Android webView 加载

编辑录入:coldstar [复制链接] [打 印]
赞助商链接