在使用 Google Play In-App Billing V5 订阅功能时,可以使用以下代码示例来实现带有试用期的订阅:
implementation 'com.android.billingclient:billing:3.0.1'
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder(); params.setSkusList(Arrays.asList(sku)) .setType(BillingClient.SkuType.SUBS);
// Add peroid duration to query subscription price String[] signatureNeeded = {"trial_period"}; params.setSkuDetailsExtraParams(new SkuDetails.SkuDetailsParams.Builder() .setIapToken(token).setDeveloperPayload(developerPayload) .setSignatureNeeded(signatureNeeded).build());
// Create a new instance of BillingClient and get the client's response listener BillingClient billingClient = BillingClient.newBuilder(context) .setListener(purchasesUpdatedListener) .enablePendingPurchases() .build();
// Call startConnection() to connect to Google Play and initiate the billing flow
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
// Query for available catalogue items, and then initiate the purchase flow.
List
实现以上代码后,用户在购买订阅时,会