콘텐츠로 건너뛰기

자주 방문한 페이지

최근 방문한 페이지

navigation

Establishing In-app Billing Products for Sale

Before publishing your In-app Billing app, you must define the product list of digital goods available for purchase in the Google Play Console.

Specify in-app products in Google Play

From the Play Console, you can define product information for in-app products and associate a product list with your app.

To add new in-app products to your product list:

  1. Build a signed APK file for your In-app Billing app. To learn how to build and sign your APK, see Prepare for Release.
  2. In the Play Console, open the app entry that you created earlier.
  3. Click on the App releases in the left-hand menu and create a release to upload your APK. You can use any channel you want, and you can start with Beta or Alpha if you don't want to publish the app now. Check our support page for details on how to Prepare & rollout releases.
  4. Navigate to the uploaded app listing, and click on In-app Products.
  5. Click on the option to add a new product, then complete the form to specify the product information such as the item's unique product ID, also called its SKU, as well as a description, price, and country availability. Note down the product ID as you may need this information to query purchase details in your app later. To see a list of the products used by the TrivialDrive_v2 sample, review the UiDelegatesFactory class.

Note: The In-app Billing service only supports managed in-app products, so make sure that you specify that the purchase type is 'Managed' when you add new items to your product list in the Play Console.

  1. Once you have completed the form, activate the product so that your app can purchase it.

Query items available for purchase

You can query Google Play to programmatically retrieve details of the in-app products that are associated with your app, such as a product's price, title, description, and type. This query is useful, for example, when you want to display a listing of unowned items that are still available for purchase to users.

Note: When making a query, you must specify the product IDs for the products explicitly. You can manually find the product IDs from the Play Console by opening the In-app Products menu for your app. The product IDs are listed under the column labeled Name/ID.

To retrieve the product details, call the asynchronous querySkuDetailsAsync() method and pass it a reference to a listener that implements the SkuDetailsResponseListener interface and a reference to a SkuDetailsParams object with a SKU list and item type. The following code shows how you can integrate this method into the BillingManager class:

public void querySkuDetailsAsync(SkuDetailParams params, final SkuDetailsResponseListener listener) {
    // Create a runnable from the request to use inside the connection retry policy.
    Runnable queryRequest = new Runnable() {
        @Override
        public void run() {
            // Create the SkuDetailParams object
            SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
            params.setSkusList(skuList).setType(itemType);
            // Run the query asynchronously.
            mBillingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(SkuDetailsResult result) {
                            listener.onSkuDetailsResponse(result);
                        }
                    });
        }
    };

    executeServiceRequest(queryRequest);
}

You must implement a retry policy to handle possible interruptions to the connection between the Play Billing Library client and the In-app Billing service. You can add a generic retry mechanism to the BillingManager class that accepts the Runnable object from the previous code sample as follows:

private void executeServiceRequest(Runnable runnable) {
    if (mIsServiceConnected) {
        runnable.run();
    } else {
        // If the billing service disconnects, try to reconnect once.
        startServiceConnection(runnable);
    }
}

If the asynchronous query is successful, the query results are stored in a List of SkuDetails objects that is passed back to the listener. The following sample code shows how you can call the querySkuDetailsAsync() method in the BillingManager class from your UI and pass it a reference to an object that implements the SkuDetailsResponseListener interface:

private void addSkuRows(final List<SkuRowData> inList, List<String> skusList,
        final @SkuType String billingType, final Runnable executeWhenFinished) {

    mBillingProvider.getBillingManager().querySkuDetailsAsync(billingType, skusList,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(@BillingResponse int responseCode,
                                                                         List<SkuDetails> skuDetailsList) {

                    if (result.getResponseCode() != BillingResponse.OK) {
                        // Handle any error responses.
                    } else if (skuDetailsList != null
                            && skuDetailsList.size() > 0) {
                            // Traverse through the list of SKUs inside SkuDetailsList.
                            ...
                }
            });
}
이 사이트는 쿠키를 사용하여 사이트별 언어 및 표시 옵션에 대한 환경설정을 저장합니다.

Google Play에서 성공을 거두는 데 도움이 되는 최신 Android 개발자 뉴스 및 도움말을 받아 보세요.

* 필수 입력란

완료되었습니다.

WeChat에서 Google Developers 팔로우하기

이 사이트를 (으)로 탐색할까요?

페이지를 요청했지만 이 사이트의 언어 환경설정은 입니다.

언어 환경설정을 변경하고 이 사이트를 (으)로 탐색할까요? 언어 환경설정을 나중에 변경하려면 각 페이지 하단의 언어 메뉴를 사용하세요.

이 클래스를 사용하려면 API 수준 이상이 필요합니다.

문서에 대해 선택한 API 수준이 이므로 이 문서가 표시되지 않습니다. 왼쪽 탐색 메뉴의 선택기로 문서 API 수준을 변경할 수 있습니다.

앱에 필요한 API 수준 지정에 관한 자세한 내용은 다양한 플랫폼 버전 지원을 참조하세요.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)