在开发过程中我我们有时可能需要使用到在Html5页面上的超链接调起QQ临时会话。使用的方法是:重写WebViewClient加上红色字体的部分,@Override不要写掉了。。。
public class MyWebViewClient extends WebViewClient {
private Context context;
public MyWebViewClient() {
}
public MyWebViewClient(Context context) {
this.context = context;
}
@Override
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
return super.shouldOverrideKeyEvent(view, event);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (url.startsWith("mqqwpa")) {
view.stopLoading();
Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
context.startActivity(in);
} else {
super.onPageStarted(view, url, favicon);
}
}
}