Android中javascript和java互相调用

阅读更多
http://www.jb51.net/article/59951.htm

mWebview = (WebView) findViewById(R.id.web_view);
		mWebview.getSettings().setJavaScriptEnabled(true);
		mWebview.getSettings().setDefaultTextEncodingName("UTF-8");	
		mWebview.setWebChromeClient(new WebChromeClient() {});
		mWebview.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);

				String json = "[{\"name\":\"zxx\", \"amount\":\"9999999\", \"phone\":\"18600012345\"}]";
	            mWebview.loadUrl("javascript:show('" + json + "')");
			}
		}); 
		mWebview.addJavascriptInterface(new WebActor(ActivitiesActivity.this), "contact");
		
		mWebview.loadUrl("file:///android_asset/index.html");


public class WebActor {
	private Activity context;
	public WebActor(Activity context) {
		this.context = context;
	}
	
	@JavascriptInterface
    public void call(String phone) {
//        startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone)));
		context.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				PromptManager.showToast(context, "拨打电话1212");
			}
		}); 
    } 
}




    
        
        Insert title here
        
    
    
       
姓名 存款 电话

你可能感兴趣的:(Android中javascript和java互相调用)