我正在我的Android应用程序中使用Google计费实现订阅功能。
我遵循了Google Play Billing的官方文档。
我已经在Play Console中创建了订阅,并将相关功能添加到了我的应用程序中。
问题是,从Play控制台没有任何订阅进入应用程序,而且billingClient!!.queryProductDetailsAsync
方法总是返回一个空的productDetailsList
。
有谁能帮我识别出这里的问题吗?
以下是我的实现方式:
在我的应用级Gradle文件中:
implementation "com.android.billingclient:billing-ktx:5.1.0"
在我的订阅文件中
private var billingClient: BillingClient? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//Setup billing
billingSetup()
}
private fun billingSetup() {
billingClient = BillingClient.newBuilder(this)
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build()
//Connect to Google Play
connectToGooglePlay()
}
private fun connectToGooglePlay() {
billingClient!!.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
Log.i("payment_flow", "OnBillingSetupFinish connected")
queryProduct()
} else {
Log.i("payment_flow", "OnBillingSetupFinish failed")
}
}
override fun onBillingServiceDisconnected() {
Log.i("payment_flow", "OnBillingSetupFinish connection lost")
//Re-connect to Google Play
connectToGooglePlay()
}
})
}
private fun queryProduct() {
val productList = ImmutableList.of(
Product.newBuilder()
.setProductId("monthly_plan")
.setProductType(BillingClient.ProductType.SUBS)
.build(),
Product.newBuilder()
.setProductId("yearly_plan")
.setProductType(BillingClient.ProductType.SUBS)
.build()
)
val queryProductDetailsParams = QueryProductDetailsParams.newBuilder()
.setProductList(productList).build()
billingClient!!.queryProductDetailsAsync(queryProductDetailsParams) {
billingResult: BillingResult, productDetailsList: List<ProductDetails> ->
Log.d("payment_flow", "onProductDetailsResponse: 1: $billingResult")
if (productDetailsList.isNotEmpty()) {
tmpProductDetailsList.addAll(productDetailsList)
Log.d("payment_flow", "onProductDetailsResponse: " + productDetailsList.size)
} else {
Log.i("payment_flow", "onProductDetailsResponse: No products")
}
}
}
提前致谢
ProductDetails
仍然为空。已经过去几个小时(至少3个小时)。您建议再等几个小时吗? - dumbfingers