您的位置:首页 > 移动开发

android app添加捐赠项,支付宝捐赠

2018-03-23 16:21 351 查看
开发自己的app一般都会设置一个捐赠,自己摸索了一段时间,写下自己发现的方式

去这个官网下载支付宝的付款码:https://qr.alipay.com

如图:



- 用微信扫一下二维码,复制网站:如下:https://qr.alipay.com/**a6x076306bxhk8outhwdr67**
- (为什么用微信的,因为微信和支付宝不兼容,不会跳转到支付宝,可以获取到链接)
我们要的就是 a6x076306bxhk8outhwdr67这一段
通过替换({替换处})`"intent://platformapi/startapp?saId=10000007&" +
"clientVersion=3.7.0.0718&qrcode=https%3A%2F%2Fqr.alipay.com%2F{替换处}%3F_s" +
"%3Dweb-other&_t=1472443966571#Intent;" +
"scheme=alipayqr;package=com.eg.android.AlipayGphone;end";`
获取自己的url然后使用intent跳转即可
/**
* 判断支付宝客户端是否已安装,建议调用转账前检查
* @return 支付宝客户端是否已安装
*/
public static   boolean hasInstalledAlipayClient() {
String ALIPAY_PACKAGE_NAME = "com.eg.android.AlipayGphone";
PackageManager pm = MyApplication.getContext().getPackageManager();
try {
PackageInfo info = pm.getPackageInfo(ALIPAY_PACKAGE_NAME, 0);
return info != null;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return false;
}
}

/***
* 支付宝转账
* @param activity
* **/
public static void openALiPay(Activity activity){
String url1="intent://platformapi/startapp?saId=10000007&" +
"clientVersion=3.7.0.0718&qrcode=https%3A%2F%2Fqr.alipay.com%2Fa6x076306bxhk8outhwdr67%3F_s" +
"%3Dweb-other&_t=1472443966571#Intent;" +
"scheme=alipayqr;package=com.eg.android.AlipayGphone;end";
//String url1=activity.getResources().getString(R.string.alipay);
Intent intent = null;
Toast.makeText(MyApplication.getContext(),"感谢您的捐赠!٩(๑❛ᴗ❛๑)۶",Toast.LENGTH_SHORT).show();
if(hasInstalledAlipayClient()){
try {
intent = Intent.parseUri(url1 ,Intent.URI_INTENT_SCHEME );
activity.startActivity(intent);
} catch (URISyntaxException e) {
e.printStackTrace();
Toast.makeText(MyApplication.getContext(),"出错啦",Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(MyApplication.getContext(),"您未安装支付宝哦!(>ω・* )ノ",Toast.LENGTH_SHORT).show();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: