根据上一篇,结合工作,实现了拨打电话,发送短信的小功能 JSP页面链接 打电话: <a href="javascript:MobileLaw.call('${model.bookUser.mobile}')">${model.bookUser.mobile } </a> 发短信: <a href="javascript:MobileLaw.goSendMessage('${model.bookUser.mobile }')"> <img src="script/img/sms.png" height="30px" width="30px"> </a> activity: 在oncreate方法中写下面代码 webView = (WebView) findViewById(R.id.dssWebView); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setDefaultTextEncodingName("UTF-8"); webView.addJavascriptInterface(this, "MobileLaw"); //注意这一个名字要和上面js中调用的名字一样 webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); 拨打电话的方法 /* * 拨打电话操作 */ public void call(final String phone){ Log.v("law","号码是 "+phone); Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + phone)); startActivity(intent); } 发送短信的方法 /* * 发送短信操作 */ public void goSendMessage(final String phone) { Log.v("law","号码是 "+phone); Uri uri = Uri.parse("smsto:"+phone); Intent intent = new Intent(Intent.ACTION_SENDTO,uri); startActivity(intent); }
最后记得加上打电话以及发短信的权限: <!-- 打电话权限 --> <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> <!-- 发短信权限 --> <uses-permission android:name="android.permission.SEND_SMS"/>
|