Google支付功能的集成步骤如下:
-
首先需要在Google开发者控制台中创建一个项目,并启用Google支付API。
-
在Android Studio中添加Google支付库依赖。在app级别的build.gradle中添加以下代码:
dependencies { ... implementation 'com.android.billingclient:billing:3.0.3' }
-
在AndroidManifest.xml文件中添加以下权限:
<uses-permission android:name="com.android.vending.BILLING" />
-
初始化BillingClient。
private BillingClient billingClient; ... billingClient = BillingClient.newBuilder(this) .enablePendingPurchases() .setListener(purchaseUpdateListener)