android 打开微信扫一扫

由于微信的更新导致不能直接通过scheme打开微信扫一扫界面,但是现在仍然有两种方式可以直接打开微信扫一扫界面:
1:

 public static void toWeChatScanDirect(Context context) {
        try {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI"));
            intent.putExtra("LauncherUI.From.Scaner.Shortcut", true);
            intent.setFlags(335544320);
            intent.setAction("android.intent.action.VIEW");
            context.startActivity(intent);
        } catch (Exception e) {
        }
    }

2:

  /**
     * 打开微信并跳入到二维码扫描页面
     *
     * @param context
     */
    public static void openWeixinToQE_Code(Context context) {
        try {
            Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
            intent.putExtra("LauncherUI.From.Scaner.Shortcut", true);
            context.startActivity(intent);

        } catch (Exception e) {
            CommonUtil.toast(ResUtil.getStringById(R.string.no_open_weixin), context);
        }
    }

其实两种方式打开原理相同,

你可能感兴趣的:(Android)