Когда вы применяете покупки в приложении, описанные на сайте developer.android, это ссылка для объяснения
Используйте Библиотеку биллинга Google Play
Все отлично, яможно узнать цену, описание и адрес товара. Проблема в том, что диалоговое окно покупки не появляется. Я использую реальный телефон
Это код покупки в приложении
class AppBilling : AppCompatActivity(), PurchasesUpdatedListener {
private lateinit var billingClient: BillingClient
private val skuList = ArrayList<String>()
override fun onPurchasesUpdated(billingResult: BillingResult?, purchases: List<Purchase>?) {
Log.i("TAG", "$billingResult :::: $purchases")
if (billingResult != null) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && purchases != null) {
for (purchase in purchases) {
Log.i("TAG", "$purchase if")
handlePurchase(purchase)
}
} else if (billingResult.responseCode == BillingClient.BillingResponseCode.USER_CANCELED) {
Log.i("TAG", "else if")
} else {
Log.i("TAG", "else")
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_app_billing)
billingClient = BillingClient.newBuilder(this@AppBilling).setListener(this).enablePendingPurchases().build()
val params = SkuDetailsParams.newBuilder()
skuList.add("rm_admob")
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP)
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult?) {
billingClient.querySkuDetailsAsync(params.build()) { billingResult, skuDetailsList ->
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
for (skuDetails in skuDetailsList) {
val sku = skuDetails.sku
val price = skuDetails.originalPrice
val title = skuDetails.title
val desc = skuDetails.description
val flowParams = BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build()
if ("rm_admob" == sku) {
id_price.text = price
id_title.text = title
id_desc.text = desc
id_rm_admob.setOnClickListener {
val responseCode = billingClient.launchBillingFlow(this@AppBilling, flowParams)
}
}
}
}
}
}
override fun onBillingServiceDisconnected() {
}
})
}
private fun handlePurchase(purchase: Purchase) {
if (purchase.sku == "rm_admob") {
Log.i("TAG", "handlePurchase()")
}
}
}
спасибо