简体   繁体   English

在 BillingClient 设置中 .setListener(this) 引用我的调用活动而不是 PurchasesUpdatedListener

[英]In BillingClient setup .setListener(this) references my calling activity instead of a PurchasesUpdatedListener

The docs show the following for setting up a Billingclient.文档显示了用于设置 Billingclient 的以下内容。

private BillingClient billingClient;
...
billingClient = BillingClient.newBuilder(activity).setListener(this).build();  

In .setListener(this), the 'this' part is supposed to reference a PurchasesUpdatedListener, even though you don't explicitly create one to put in these parenthesis.在 .setListener(this) 中,'this' 部分应该引用一个 PurchasesUpdatedListener,即使您没有明确地创建一个放在这些括号中。 Apparently just using 'this' is supposed to be enough.显然只使用'this'就足够了。 In the docs and all the examples I've seen, a PurchasesUpdatedListener is never created to put here, it just uses 'this', apparently self-referencing the billingclient being created.在文档和我见过的所有示例中,从来没有创建一个 PurchasesUpdatedListener 来放在这里,它只是使用“this”,显然是自引用正在创建的 billingclient。 This hasn't worked for me though, and I keep getting:不过,这对我不起作用,而且我不断收到:

在此处输入图片说明

Should I use something else for the (activity) part than (getApplicationContext())?我应该为(活动)部分使用其他东西而不是(getApplicationContext())吗? I've tried (this) and various other things here as just the word 'activity' isn't recognized.我在这里尝试过(这个)和其他各种事情,因为只有“活动”这个词不被识别。

Instead setListener(this) put setListener(new PurchasesUpdatedListener(){... }) and implement the required methods (usually AndroidStudio does it automatically)相反setListener(this)setListener(new PurchasesUpdatedListener(){... })并实现所需的方法(通常 AndroidStudio 会自动执行)

Or或者

add .. implements PurchasesUpdatedListener at the end of your MainActivity declaration在 MainActivity 声明的末尾添加 .. implements PurchasesUpdatedListener

the same thing as you can do on many listeners, for example the well known OnClickListener与您可以对许多侦听器执行的操作相同,例如众所周知的 OnClickListener

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android IABHelper 与 Billingclient - Android IABHelper vs Billingclient 如何在 billingClient.queryProductDetailsAsync 方法中为我的所有按钮设置价格购买 - How set price purchase on all my buttons in billingClient.queryProductDetailsAsync method 整个应用程序中BillingClient的一个实例 - One instance of BillingClient throughout app Android - BillingClient 返回空购买列表 - Android - BillingClient returns empty purchases list paymentquue UpdatedTransactions:未调用,而是paymentQueueRestoreCompletedTransactionsFinished:正在调用 - paymentquue updatedTransactions: not called instead paymentQueueRestoreCompletedTransactionsFinished: calling Android Google BillingClient 如何获取未消耗的物品? - Android Google BillingClient how to get unconsumed items? 无法使用com.android.billingclient:billing获得SkuDetail - cannot get SkuDetail using com.android.billingclient:billing 在完成inapp购买后,billingclient.querypurchase()。getPurchaseList()返回null - After completion of inapp purchase billingclient.querypurchase().getPurchaseList() is returning null Google Play ANR com.android.billingclient.api.BillingClientStateListener.onBillingSetupFinished - Google Play ANR com.android.billingclient.api.BillingClientStateListener.onBillingSetupFinished 升级到 billingclient:billing:2.1.0 后,IabHelper 不再导入 android.vending.billing.IInAppBillingService - IabHelper no longer imports android.vending.billing.IInAppBillingService after upgrading to billingclient:billing:2.1.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM