1

here is the code can anyone tell how can I setSkuDetails() as I was using vision one now I update it to 4 However, setSku and setType seem to be deprecated in the BillingFlowParams.Builder class. Instead, we should be using setSkuDetails(SkuDetails).

    private void BillingFunction() {
        mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        // Establish connection to billing client
        mBillingClient = BillingClient.newBuilder(MainActivity.this).setListener(MainActivity.this).build();
        mBillingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    // The billing client is ready. You can query purchases here.
                    getPricesMonthlyTime();
                    getPricesYearlyTime();
                    getPricesONeTime();
                }
            }

            @Override
            public void onBillingServiceDisconnected() {
                //TODO implement your own retry policy
                Toast.makeText(MainActivity.this, getResources().getString(R.string.billing_connection_failure), Toast.LENGTH_SHORT);
                // Try to restart the connection on the next request to
                // Google Play by calling the startConnection() method.
            }
        });


        continue_button.setOnClickListener(view -> {
            if (select_radio_one.getVisibility() == View.VISIBLE) {
                BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                        .setSkuDetails()
                        .build();

                BillingResult responseCode = mBillingClient.launchBillingFlow(MainActivity.this, flowParams);
                brandDialogInAppPurchase.dismiss();
            } else if (select_radio_two.getVisibility() == View.VISIBLE) {
                BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                        .setSkuDetails()
                        .build();

                BillingResult responseCode = mBillingClient.launchBillingFlow(MainActivity.this, flowParams);

                brandDialogInAppPurchase.dismiss();
            } else if (select_radio_three.getVisibility() == View.VISIBLE) {
                BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                        .setSkuDetails()
                        .build();

                BillingResult responseCode = mBillingClient.launchBillingFlow(MainActivity.this, flowParams);
                brandDialogInAppPurchase.dismiss();
            } else {
                Toast.makeText(MainActivity.this, "Nothing selected", Toast.LENGTH_SHORT).show();
            }

        });

//          queryPrefPurchases();
        queryPurchases();

    }

1 Answers1

0

You should send the object skuDetail. To do so you need to retrieve it by calling querySkuDetailsAsync().

fun querySkuDetails() {
    val skuList = ArrayList<String>()
    skuList.add("premium_upgrade")
    skuList.add("gas")
    val params = SkuDetailsParams.newBuilder()
    params.setSkusList(skuList).setType(SkuType.INAPP)

    // leverage querySkuDetails Kotlin extension function
    val skuDetailsResult = withContext(Dispatchers.IO) {
        billingClient.querySkuDetails(params.build())
    }

    // Process the result.
}
Nicolas
  • 663
  • 6
  • 17