微信
在自己的应用中打开微信扫一扫代码:
private void toWeChatScan() {
try {
//利用Intent打开微信
Uri uri = Uri.parse("weixin://dl/scan");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} catch (Exception e) {
//若无法正常跳转,在此进行错误处理
Toast.makeText(context, "无法跳转到微信,请检查是否安装了微信", Toast.LENGTH_SHORT).show();
}
}
使用以上代码跳转到微信(版本:6.3.18)扫一扫,会出现以下情况:
情况: 结果:
安装并登陆了微信 跳转到微信扫一扫
安装了但未登陆微信 跳转到微信登陆,登陆成功后跳转到扫一扫
未安装微信 Toast没安装微信
现在微信不能直接跳转到微信扫一扫,只能跳到微信首页:
①方法一:将代码
Uri uri = Uri.parse("weixin://dl/scan");
改为
Uri uri = Uri.parse("weixin://");
②方法二:通过包名打开微信
Intent intent = getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
startActivity(intent);
支付宝
private void toAliPayScan() {
try {
//利用Intent打开支付宝
//支付宝跳过开启动画打开扫码和付款码的urlscheme分别是:
//alipayqr://platformapi/startapp?saId=10000007
//alipayqr://platformapi/startapp?saId=20000056
Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=10000007");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} catch (Exception e) {
//若无法正常跳转,在此进行错误处理
Toast.makeText(context, "打开失败,请检查是否安装了支付宝", Toast.LENGTH_SHORT).show();
}
}