Android,iOS打开手机QQ与指定用户聊天界面

跨平台启动QQ聊天
本文介绍了一种通过特定代码在不同平台上启动QQ聊天的方法。在Android、iOS和浏览器环境中均可实现,适用于创建客服QQ等场景。

在浏览器中能够通过JS代码打开QQ并弹出聊天界面。一般作为客服QQ使用。

而在移动端腾讯貌似没有发布提供相似API,可是却能够使用schema模式来启动手机QQ。

下面为详细代码:

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>

打开指定用户的微博页面:

            if (com.sina.weibo.sdk.ApiUtils.validateWeiboSign(context, "com.sina.weibo")) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("sinaweibo://userinfo?uid=" + weiboId));
                Intent chooseIntent = Intent.createChooser(intent, "Weibo");
                context.startActivity(chooseIntent);
            } else {
                NavigateHelper.startWebview(context, "http://weibo.com/u/" + weiboId);
            }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值