bp = new BillingProcessor(this, "YOUR LICENSE KEY FROM GOOGLE PLAY CONSOLE HERE", this);
bp.initialize();
您将获得以下信息 override 方法,
@Override
public void onBillingInitialized() {
/*
* Called when BillingProcessor was initialized and it's ready to purchase
*/
}
@Override
public void onProductPurchased(String productId, TransactionDetails details) {
/*
* Called when requested PRODUCT ID was successfully purchased
*/
}
@Override
public void onBillingError(int errorCode, Throwable error) {
/*
* Called when some error occurred. See Constants class for more details
*
* Note - this includes handling the case where the user canceled the buy dialog:
* errorCode = Constants.BILLING_RESPONSE_RESULT_USER_CANCELED
*/
}
@Override
public void onPurchaseHistoryRestored() {
/*
* Called when purchase history was restored and the list of all owned PRODUCT ID's
* was loaded from Google Play
*/
}
2条答案
按热度按时间uxh89sit1#
有一个伟大的图书馆,我希望能帮助你解决你的问题,因为我已经在一些产品中使用它。你可以试试这个图书馆
这个图书馆能很好地处理
Subscriptions
以及Purchases
有无有效载荷。你只需要把implementation 'com.anjlab.android.iab.v3:library:1.0.44'
在你的build.gradle
你可以走了。当你的
build.gradle
准备就绪,实施BillingProcessor.IBillingHandler
用你的activity
.然后将此代码放入
onCreate
.您将获得以下信息
override
方法,这是诀窍,
onPurchaseHistoryRestored
是你要找的实际方法。只要有错误,就会调用此方法subscription
或者purchase
已针对特定电子邮件提供。这个库将自动为您处理它。如果对你有帮助就告诉我。别忘了加上这个
<uses-permission android:name="com.android.vending.BILLING" />
在您的Manifest
.zi8p0yeb2#
如果要查询在不同设备上登录到同一帐户的用户的订阅状态,可以使用billingclient.querypurchases()接口查询订阅状态。如果接口返回订阅,则它在订阅有效期内,您需要继续提供服务。