1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Android调用微信扫一扫和支付宝扫一扫

Android调用微信扫一扫和支付宝扫一扫

时间:2021-05-22 04:18:36

相关推荐

Android调用微信扫一扫和支付宝扫一扫

微信

在自己的应用中打开微信扫一扫代码:

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=20000056Uri 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();}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。