android webview自定义标签!(实现打电话的功能);

来源:互联网 发布:windows7 apache 编辑:程序博客网 时间:2024/06/06 01:13

android自定义标签需要使用到的类有webviewClient这个类;我们要做的是重写这里面的一个方法;这个重写的方法里有一个参数是url;我们就要用到url;

我在这里需要用到有activity;layout;html文件;在javascript调用android打电话;还需要添加打电话权限哦;

layout文件主要就是一个webview控件;

java代码;如下;

package com.tarena.chat.view;import com.tarena.chat.R;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.webkit.WebView;import android.webkit.WebViewClient;public class HelpActivity extends Activity{    private WebView webview;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.help_layout);        webview=(WebView)findViewById(R.id.gridView1);        webview.loadUrl("file:///android_asset/help.html");        webview=new WebView(getApplicationContext());        webview.setWebViewClient(new WebViewClient(){            @Override            public boolean shouldOverrideUrlLoading(WebView view, String url) {                if (url.contains("tarena/tell:")) {                    String index="tarena/tell:";                    String phone=url.substring(index.indexOf("tarena/tell".length()));                    Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tell"+phone));                    startActivity(intent);                }                return super.shouldOverrideUrlLoading(view, url);            }        });    }}


html文件如下;我在这里是将html文件放到了asset目录下;

<html><head><body>    <p>欢迎使用天天聊天软件</p>    <p>这个软件使用很方便</p>    <p>这个软件使用很方便</p>    <p>这个软件使用很方便</p>    <p>这个软件使用很方便</p>    <p>这个软件使用很方便</p>    <p>这个软件使用很方便</p>    <a href="tarena/tell:13265562350">联系我们</a>    <a href="http://blog.csdn.net/android_drawing">访问官方博客</a></body></head></html>

ok啦;


0 0
原创粉丝点击