1. Check whether the QQ client is installed

    /** * QQ package name */
    public static final String PACKAGENAME_QQ = "com.tencent.mobileqq";

    /** * Check whether the application is installed */
    public static boolean checkApkInstalled(Context context, String packageName) {
        if (TextUtils.isEmpty(packageName)) {
            return false;
        }
        try {
            ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName, 0);
            returninfo ! =null;
        } catch (PackageManager.NameNotFoundException e) {
            return false; }}Copy the code

2. Open the specified QQ chat page

    /** * Open the specified QQ chat page **@paramContext *@paramQQ QQ number */
    public static boolean openQQChat(Context context, String QQ) {
        try {
            String url = "mqqwpa://im/chat? chat_type=wpa&uin=" + QQ;
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            return false; }}Copy the code

Note: If the QQ number specified in this method is not added as a friend, the QQ promotion function should be opened on the OFFICIAL website of QQ promotion. Otherwise, sending temporary messages to this QQ number will fail.

3. Open the specified QQ group

Method one:

    /** * Open the specified QQ group chat page **@paramContext *@paramGroup QQ group number */
    public static boolean openQQGroup(Context context, String group) {
        try {
            String url = "mqqwpa://im/chat? chat_type=group&uin=" + group;
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            return false; }}Copy the code

Note: this method can only open the QQ group that you have joined.

Method 2:

    /** * Open the specified QQ group chat page **@paramContext *@paramKey Indicates the key */ generated by QQ official website
    public static boolean joinQQGroup(Context context, String key) {
        try {
            String url = "mqqopensdkapi://bizAgent/qm/qr? url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + key;
            Intent intent = new Intent();
            intent.setData(Uri.parse(url));
            // This Flag can be customized according to specific product requirements. If it is set, press Back on the group add screen to return to the mobile Q main screen. If it is not set, press Back to return to the call product screen
            // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            return false; }}Copy the code

Note: To open the Key required by the specified QQ group, you can select the required QQ group on the official website to generate the corresponding Key.