Android Google Pay 集成

4. 连接 Google Play Service


在使用支付功能之前,首先要连接Google Play Service,确保当前状态支付是可用的,此操作对于国内用户来说是需要梯子的,但是对于国外的用户,就不用操心了,毕竟我们开发Google Play主要还是给国外用户使用。

billingClient.startConnection(object : BillingClientStateListener {

override fun onBillingSetupFinished(@BillingClient.BillingResponse billingResponseCode: Int) {

// 连接成功

if (billingResponseCode == BillingClient.BillingResponse.OK) {

// The billing client is ready. You can query purchases here.

// 5. Query for in-app product details.

// 5. 查询商品详情

// 6. 支付商品

} else {

// TODO 连接失败

}

}

// 连接断开

override fun onBillingServiceDisconnected() {

// Try to restart the connection on the next request to

// Google Play by calling the startConnection() method.

}

})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值