我正在编写一个免费的Android应用程序。购买InApp后,您可以一次解锁其他功能。 我正在使用InAppBillingV3来使用它。
我在活动中创建计费处理器
try {
bp = BillingProcessor(this,"...",this)
bp!!.initialize()
} catch(e:Exception) {
Log.e(Utils.LOG_TAG, e.message, e)
}
我购买了我的物品
fun purchaseProversion () : Boolean {
try {
if(inAppServiceAvailable()) {
return bp!!.purchase(this, PROVERSION_PLAY_STORE_ID)
}
} catch(e:Exception) {
Log.e(Utils.LOG_TAG, e.message, e)
}
return false
}
我希望到目前为止都是正确的。
出于测试原因,我正在将“ android.test.purchased”用作PROVERSION_PLAY_STORE_ID
我想检查用户单击按钮时是否已经购买了产品。 像这样:
fun startProFeature() {
if(proversionAlreadyPurchased()) {
// start feature
} else {
// show dialog that the user needs the proversion
purchaseProversion()
}
}
fun proversionAlreadyPurchased() : Boolean {
// TODO TBD
return false
}
推荐的实现方式是什么? (方法:proversionAlreadyPurchaeded)
答案 0 :(得分:0)
这是我的工作解决方案
bp!!.loadOwnedPurchasesFromGoogle()
var ownedProducts = bp!!.listOwnedProducts()
if(ownedProducts != null) {
var found = ownedProducts.find { it == PROVERSION_PLAY_STORE_ID }
var proversion = found != null