0

最近我从 3.0.2 升级到了 Android BillingClient 版本 4.0.0。我在异步函数中面临 2 个问题。在 Async 函数中编写的 UI 代码(例如显示 AlertDialog 和禁用按钮)不起作用。在 billingClient.queryPurchaseHistoryAsync() 中显示 AlertDialog 在 billingclient 版本 4.0.0 中不起作用。这在 3.0.2 版中运行良好。同样,禁用 billingClient.queryPurchasesAsync() 中的按钮在 billingclient 版本 4.0.0 中不起作用。

代码如下。请指导我如何解决这个问题。提前致谢。

public class SubscribeActivity extends AppCompatActivity implements
    PurchasesUpdatedListener, BillingClientStateListener,
    AcknowledgePurchaseResponseListener {

private Button btnSubscribe;
private BillingClient billingClient;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_subscribe);

    btnSubscribe = findViewById(R.id.btnSubscribe);
    billingClient = BillingClient.newBuilder(this).setListener(this)
            .enablePendingPurchases().build();
}

private void generatePurchaseDetails() {

        billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS,
                (billingResult, purchaseList) -> {

                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    // some more code here...
                    builder.create().show();
                    // This AlertDialog is not getting displayed in billingclient version 4.0.0. This was working fine in version 3.0.2.
        });
}

private void queryPurchases() {

    billingClient.queryPurchasesAsync(BillingClient.SkuType.SUBS,
            (billingResult, purchases) -> {
          
          // The below line is not getting executed properly in billingclient 4.0.0.
          btnSubscribe.setEnabled(false);
          // some more code here...The control does not come to these lines of code.
    });
}

}

4

0 回答 0