Reminder: By Aug 31, 2025, all new apps and updates to existing apps must use Billing Library version 7 or newer. If you need more time to update your app, you can request an extension until Nov 1, 2025. Learn about Play Billing Library version deprecation.
if(skuDetails.isRewarded()){valparams=RewardLoadParams.Builder().setSkuDetails(skuDetails).build()mBillingClient.loadRewardedSku(params.build(),object:RewardResponseListener{overridefunonRewardResponse(@BillingResponseresponseCode:Int){if(responseCode==BillingResponse.OK){// Enable the reward product, or make// any necessary updates to the UI.}}})}
Java
if(skuDetails.isRewarded()){RewardLoadParams.Builderparams=RewardLoadParams.newBuilder();params.setSkuDetails(skuDetails);mBillingClient.loadRewardedSku(params.build(),newRewardResponseListener(){@OverridepublicvoidonRewardResponse(intresponseCode){if(responseCode==BillingResponse.OK){// Enable the reward product, or make// any necessary updates to the UI.}}});}
向用户提供奖励购买
如果 Google Play 结算库成功加载与奖励商品关联的视频(即,如果 RewardResponseListener 收到的 responseCode 为 BillingResponse.OK),您便可以启动结算流程。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Add rewarded-product-specific features\n\n| **Warning:** Rewarded products are no longer supported. For more information, see [Create a rewarded product](https://support.google.com/googleplay/android-developer/answer/9155268).\n\nOne method of unlocking in-app products and benefits for your users is to create\n*rewarded products*, or items that users receive after they watch a video\nadvertisement. By providing rewarded products, you allow users to obtain in-app\nrewards and benefits without them having to make direct purchases.\n\nThis document explains how to implement functionality specific to rewarded\nproducts. The [workflow diagram](#workflow-diagram) section of this page\nillustrates the process.\n\nIdentify your app's rewarded products\n-------------------------------------\n\nRewarded products have a\n[`SkuType`](/reference/com/android/billingclient/api/BillingClient.SkuType) of\n[`INAPP`](/reference/com/android/billingclient/api/BillingClient.SkuType#INAPP).\nTo ensure users are able to watch multiple ads and get multiple rewards, the\nproducts need to be consumed.\n\nBefore you can offer a rewarded product to a user, you must obtain the\n[`SkuDetails`](/reference/com/android/billingclient/api/SkuDetails) for the\nproduct. To do this, call\n[`querySkuDetailsAsync()`](/reference/com/android/billingclient/api/BillingClient#queryskudetailsasync)\nwith `SkuType.INAPP` as the product type.\n\nDeclare age-appropriate ads\n---------------------------\n\nTo help facilitate compliance with legal obligations related to children and to\nunderage users, including the [Children's Online Privacy Protection Act\n(COPPA)](http://business.ftc.gov/privacy-and-security/childrens-privacy)\nand the [General Data Protection Regulation\n(GDPR)](http://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32016R0679),\nyour app should declare which ads should be treated as child-directed in the United\nStates and which ads are directed at users who are under [the applicable age of consent in\ntheir country](https://support.google.com/accounts/answer/1350409). The AdMob\nHelp Center explains when you should tag your ad requests for [child-directed\ntreatment](https://support.google.com/admob/answer/6219315) and when you should\ntag them for [under-the-age-of-consent\ntreatment](https://support.google.com/admob/answer/9009425), as well as the\neffects of doing so.\n\nAs you create your app's billing client, consider whether the rewarded ad\nrequests should be treated as child-directed or whether they should be directed\nat users who are under the age of consent. If the ad requests should have these\nrestrictions in place, call the\n[`setChildDirected()`](/reference/com/android/billingclient/api/BillingClient#setchilddirected)\nand\n[`setUnderAgeOfConsent()`](/reference/com/android/billingclient/api/BillingClient#setunderageofconsent)\nmethods, passing appropriate values into each method.\n\nThe following code snippet shows how to declare that video ads should be\nsuitable for children or for users who are under the age of consent: \n\n### Kotlin\n\n```kotlin\nval billingClient = BillingClient.newBuilder(context)\n .setListener(this)\n .setChildDirected(ChildDirected.CHILD_DIRECTED)\n .setUnderAgeOfConsent(UnderAgeOfConsent.UNDER_AGE_OF_CONSENT)\n .build()\n```\n\n### Java\n\n```java\nBillingClient billingClient =\n BillingClient.newBuilder(context)\n .setListener(this)\n .setChildDirected(ChildDirected.CHILD_DIRECTED)\n .setUnderAgeOfConsent(UnderAgeOfConsent.UNDER_AGE_OF_CONSENT)\n .build();\n```\n| **Note:** After you've created a billing client, you cannot change the values for `childDirected` and `underAgeOfConsent`. If you need to use different values, such as when the user switches game accounts, disconnect your current billing client, make a new instance of the client, and connect that new instance to the Google Play Billing Library.\n\nLoad video ads\n--------------\n\nBefore showing your user an option to watch a video ad in order to receive a\nrewarded product, you need to load the video. To do so, create a\n[`RewardLoadParams`](/reference/com/android/billingclient/api/RewardLoadParams) object, associating it with the `SkuDetails` object that\nrepresents the rewarded product. Then, call your billing client's\n[`loadRewardedSku()`](/reference/com/android/billingclient/api/BillingClient#loadrewardedsku)\nmethod, passing in the `RewardLoadParams` object and a\n[`RewardResponseListener`](/reference/com/android/billingclient/api/RewardResponseListener)\nobject.\n| **Note:** Video ads associated with rewarded products aren't always available for loading. Also, depending on the user's bandwidth, available videos could take some time to load.\n\nThe `RewardResponseListener` listener is notified when the video has finished\nloading. The listener is also notified if the video is unavailable or if another\nerror, such as a server timeout, occurs.\n\nTo maintain device performance when loading the videos associated with your\napp's rewarded products, keep the following best practices in mind:\n\n- Load at most three rewarded product SKUs at a time.\n- Attempt to load the videos whenever the user enters your app. This step helps you check whether the videos are still loaded and available.\n- When deciding when to load the videos, choose the balance between bandwidth\n usage and app responsiveness that works best for your use case:\n\n - At the earliest, load the videos after you call `getSkuDetails()` for the associated rewarded product. Your app remains very responsive, but you might waste network data loading a video that the user never watches.\n - At the latest, load the video when the user navigates to the page where the video is to be displayed. Your app rarely wastes bandwidth in this case, but the user might have to wait a few moments before the button for watching the video becomes clickable.\n\nThe following code snippet demonstrates the process for loading a video ad that\nplays before the user receives the rewarded product:\n\n\u003cbr /\u003e\n\n### Kotlin\n\n```kotlin\nif (skuDetails.isRewarded()) {\n val params = RewardLoadParams.Builder()\n .setSkuDetails(skuDetails)\n .build()\n mBillingClient.loadRewardedSku(params.build(),\n object : RewardResponseListener {\n override fun onRewardResponse(@BillingResponse responseCode : Int) {\n if (responseCode == BillingResponse.OK) {\n // Enable the reward product, or make\n // any necessary updates to the UI.\n }\n }\n })\n}\n```\n\n### Java\n\n```java\nif (skuDetails.isRewarded()) {\n RewardLoadParams.Builder params = RewardLoadParams.newBuilder();\n params.setSkuDetails(skuDetails);\n mBillingClient.loadRewardedSku(params.build(),\n new RewardResponseListener() {\n @Override\n public void onRewardResponse(int responseCode) {\n if (responseCode == BillingResponse.OK) {\n // Enable the reward product, or make\n // any necessary updates to the UI.\n }\n }\n });\n}\n```\n\n\u003cbr /\u003e\n\nGive rewarded purchases to users\n--------------------------------\n\nIf the Google Play Billing Library successfully loads the video associated with\na rewarded product---that is, if the `RewardResponseListener` receives a\n`responseCode` of\n[`BillingResponse.OK`](/reference/com/android/billingclient/api/BillingClient.BillingResponse#OK)---you\ncan launch the billing flow.\n| **Caution:** Don't start the billing flow if the `responseCode` isn't `BillingResponse.OK`, which happens if the video ad isn't available. That way, you don't show extra error dialogs, which maintains a good user experience.\n\nYou start playing ads for a rewarded product by calling\n[`launchBillingFlow()`](/reference/com/android/billingclient/api/BillingClient#launchbillingflow),\nas you do for [all other types of in-app\nproducts](/google/play/billing/billing_library_overview#Enable). Even though the\nuser isn't making a direct purchase to receive a rewarded product, you still\nneed to enable the billing flow so that the user is able to obtain and use the\nproduct.\n\nConsume the purchase\n--------------------\n\nTo notify your billing client that a user has received and consumed a rewarded\nproduct, [handle the\npurchase](/google/play/billing/billing_library_overview#HandlePurchase) in your\nbilling client listener's\n[`onPurchasesUpdated()`](/reference/com/android/billingclient/api/PurchasesUpdatedListener#onpurchasesupdated)\nmethod. Note that rewarded purchases [need to be consumed](/google/play/billing/billing_onetime#indicate_a_one-time_product_has_been_consumed).\n\nTest your rewarded products\n---------------------------\n\nTo test how your app loads video ads and provides users with rewarded products,\nmake use of *licensed testers* , who by default get test ads instead of real\nones. To learn how to set up accounts for these testers, see [User-test a Google\nPlay Billing app](/google/play/billing/billing_testing#testing-purchases).\n\nAnother method of testing is for you to use the `android.test.reward` product\nID. This specific product is a reserved name in Google Play Billing, so you\ndon't need to add it to your list of in-app products in the Play Console. \n**Caution:** When testing your app's rewarded products, **don't use\nactual products**; otherwise, your account might be flagged as a spam or\nfraudulent account.\n\nWhen you're done testing, however, make sure you replace\n`android.test.reward` with the product IDs for your actual rewarded\nproducts before you deploy your production app to end users.\n\nDiagram of rewarded product workflow\n------------------------------------\n\nThe following sequence diagram shows how the user, your app, and the\nGoogle Play Billing Library work together to show a video ad and grant the\nuser access to a rewarded product:\n**Figure 1.** Steps for completing a rewarded product purchase using Google Play Billing"]]