现在的位置: 首页 > 综合 > 正文

android 实现拨打jsp页面电话功能

2018年04月07日 ⁄ 综合 ⁄ 共 1224字 ⁄ 字号 评论关闭

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"/>

转载出处

抱歉!评论已关闭.