问题前言
在开发安卓应用时,经常会遇到一键加QQ群的功能,安卓端可以通过填写QQ群安卓key,直接跳到此QQ群页面,那么该如何获取QQ群链接的key呢?
解决方案
打开下面QQ群的官方一键加群页面:
使用自己的QQ号登陆,找到对应QQ群,即可看到QQ群对应的key和相应的代码。
上图中我已经标记出来了,这就是QQ群安卓的key
开发安卓程序跳转QQ群的源码:
/**************** * * 发起添加群流程。 * 你的QQ群的key为:7i_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx * @param key 由官网生成的key * @return 返回true表示呼起手Q成功,返回false表示呼起失败 ******************/ public boolean joinQQGroup(String key) { Intent intent = new Intent(); intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + key)); // 此Flag可根据具体产品需要自定义,如设置,则在加群界面按返回,返回手Q主界面,不设置,按返回会返回到呼起产品界面 //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) try { startActivity(intent); return true; } catch (Exception e) { // 未安装手Q或安装的版本不支持 return false; } }
使用提示
请根据自己实际情况做相应修改
如有什么BUG或者疑问欢迎各路大神补充&指正