在浏览器中可以通过JS代码打开QQ并弹出聊天界面,一般作为客服QQ使用。而在移动端腾讯貌似没有公布提供类似API,但是却可以使用schema模式来启动手机QQ。
//以打开微信为例,前提需要知道打开应用的包名,一般一个发布版本的应用,包名不会轻易改变的,但是,打开QQ就要注意了,毕竟QQ的发布版本有不下于4个版本。
Intent intent = getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
startActivity(intent);
以下为具体代码:
Android:
String url="mqqwpa://im/chat?chat_type=wpa&uin=123456";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
iOS:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSURL *url = [NSURL URLWithString:@"mqq://im/chat?chat_type=wpa&uin=123456&version=1&src_type=web"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
webView.delegate = self;
[webView loadRequest:request];
[self.view addSubview:webView];
浏览器:
<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=123456&site=qq&menu=yes">click here</a>
//以打开微信为例,前提需要知道打开应用的包名,一般一个发布版本的应用,包名不会轻易改变的,但是,打开QQ就要注意了,毕竟QQ的发布版本有不下于4个版本。
Intent intent = getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
startActivity(intent);
以下为具体代码:
Android:
String url="mqqwpa://im/chat?chat_type=wpa&uin=123456";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
iOS:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSURL *url = [NSURL URLWithString:@"mqq://im/chat?chat_type=wpa&uin=123456&version=1&src_type=web"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
webView.delegate = self;
[webView loadRequest:request];
[self.view addSubview:webView];
浏览器:
<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=123456&site=qq&menu=yes">click here</a>