如何在项目集成添加QQ群方案


在自己的项目中集成官方加群方案,如果没有安装QQ则下载QQ

代码比较粗糙 不喜欢勿看
一键加群组件

public static void  getQQ(final Activity context) {
  AlertDialog dialog = new AlertDialog.Builder(context)
            .setTitle("加入QQ群")//设置对话框的标题
            .setItems(R.array.qq_items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                        case 0:
                            joinQQGroup(context,"QQ群 key ");
                            break;
                        case 1:
                            joinQQGroup(context, "QQ群 key ");
                            break;
                        case 2:
                            joinQQGroup(context,"QQ群 key ");
                            break;
                    }
                    dialog.dismiss();
                }
            })
            .create();
    dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
    dialog.show();
}
public static boolean joinQQGroup(final Context context,String str) {
    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%26k%3D" + str));
    try {
        context. startActivity(intent);
        return true;
    } catch (Exception e) {
        AlertDialog builder = new AlertDialog.Builder(context)
                .setIcon(R.drawable.ic_alert)//设置标题的图片
                .setTitle("没有QQ客服端")//设置对话框的标题
                .setMessage("你的设备上没有QQ.请下载最新版本!")//设置对话框的内容
                //设置对话框的按钮
                .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        dialog.dismiss();
                    }
                })
                .setPositiveButton("马上下载", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        goToMainAppsMarketQQ(context);
                        dialog.dismiss();
                    }
                }).create();

        builder.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
        builder.show();
        return false;
    }
}

public static void goToMainAppsMarketQQ(final Context context) {
    Uri uri = Uri.parse("http://www.samsungapps.com/appquery/appDetail.as?appId=" + "com.tencent.mobileqq");
    final Intent goToMarket = new Intent();
    goToMarket.setClassName("com.sec.android.app.samsungapps", "com.sec.android.app.samsungapps.Main");
    goToMarket.setData(uri);
    try {
        context.startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        AlertDialog builder = new AlertDialog.Builder(context)
                .setIcon(R.drawable.ic_alert)//设置标题的图片
                .setTitle("麻烦啦")//设置对话框的标题
                .setMessage("没有发现三星商店,是否跳转到可用的市场下载?")//设置对话框的内容
                //设置对话框的按钮
                .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        dialog.dismiss();
                    }
                })
                .setPositiveButton("马上下载", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        goToMarketQQ(context);
                    }
                }).
                        create();
        builder.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
        builder.show();
        e.printStackTrace();
    }
}
public static void goToMarketQQ(Context context) {
    Uri uri = Uri.parse("market://details?id=" + "com.tencent.mobileqq");
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    try {
        context.startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}

声明:本网站采用BY-NC-SA协议进行授权

版权:LeoROM丨FusionLeo内核丨三星S9丨三星S8|版权所有,违者必究|如未注明,均为原创

转载:转载请注明原文链接 - 如何在项目集成添加QQ群方案


不忘初心 方得始终