diff --git a/docs/html/guide/market/billing/billing_admin.jd b/docs/html/guide/market/billing/billing_admin.jd index 38099ee079d95..723113dc80e4f 100755 --- a/docs/html/guide/market/billing/billing_admin.jd +++ b/docs/html/guide/market/billing/billing_admin.jd @@ -15,118 +15,214 @@ parent.link=index.html

Downloads

    -
  1. Sample Application
  2. +
  3. Sample + Application

See also

    -
  1. Overview of In-app Billing
  2. -
  3. Implementing In-app Billing
  4. -
  5. Security and Design
  6. -
  7. Testing In-app Billing
  8. -
  9. In-app Billing Reference
  10. +
  11. Overview of In-app + Billing
  12. +
  13. Implementing In-app + Billing
  14. +
  15. Security and + Design
  16. +
  17. Testing In-app + Billing
  18. +
  19. In-app Billing + Reference
-

In-app billing frees you from processing financial transactions, but you still need to perform a few administrative tasks, including setting up and maintaining your product list on the publisher site, registering test accounts, and handling refunds when necessary.

+

In-app billing frees you from processing financial transactions, but you still need to perform a +few administrative tasks, including setting up and maintaining your product list on the publisher +site, registering test accounts, and handling refunds when necessary.

-

You must have an Android Market publisher account to register test accounts. And you must have a Google Checkout Merchant account to create a product list and issue refunds to your users. If you already have a publisher account on Android Market, you can use your existing account. You do not need to register for a new account to support in-app billing. If you do not have a publisher account, you can register as an Android Market developer and set up a publisher account at the Android Market publisher site. If you do not have a Google Checkout Merchant account, you can register for one at the Google Checkout site.

+

You must have an Android Market publisher account to register test accounts. And you must have a +Google Checkout Merchant account to create a product list and issue refunds to your users. If you +already have a publisher account on Android Market, you can use your existing account. You do not +need to register for a new account to support in-app billing. If you do not have a publisher +account, you can register as an Android Market developer and set up a publisher account at the +Android Market publisher site. If you do not have a +Google Checkout Merchant account, you can register for one at the Google Checkout site.

Creating a Product List

-

The Android Market publisher site provides a product list for each of your published applications. You can sell an item using Android Market's in-app billing feature only if the item is listed on an application's product list. Each application has its own product list; you cannot sell items that are listed in another application's product list.

+

The Android Market publisher site provides a product list for each of your published +applications. You can sell an item using Android Market's in-app billing feature only if the item is +listed on an application's product list. Each application has its own product list; you cannot sell +items that are listed in another application's product list.

-

You can access an application's product list by clicking the In-App Products link that appears under each of the applications that are listed for your publisher account (see figure 1). The In-App Products link appears only if you have a Google Checkout Merchant account and an application's manifest includes the com.android.vending.BILLING permission.

+

You can access an application's product list by clicking the In-App Products +link that appears under each of the applications that are listed for your publisher account (see +figure 1). The In-App Products link appears only if you have a Google Checkout +Merchant account and an application's manifest includes the com.android.vending.BILLING +permission.

- Figure 1. You can access an application's product list by clicking the In-App Products link. + Figure 1. You can access an application's product list by clicking the + In-App Products link.

-

A product list contains information about the items you are selling, such as a product id, product description, and price (see figure 2). The product list stores only metadata about the items you are selling in your application. It does not store any digital content. You are responsible for storing and delivering the digital content that you sell in your applications.

+

A product list contains information about the items you are selling, such as a product id, +product description, and price (see figure 2). The product list stores only metadata about the items +you are selling in your application. It does not store any digital content. You are responsible for +storing and delivering the digital content that you sell in your applications.

Figure 2. An application's product list.

-

You can create a product list for a published application or a draft application that's been uploaded and saved to the Android Market site. However, you must have a Google Checkout Merchant account and the application's manifest must include the com.android.vending.BILLING permission. If an application's manifest does not include this permission, you will be able to edit existing items in the product list but you will not be able to add new items to the list. For more information, see Modifying your application's AndroidManifest.xml file.

+

You can create a product list for a published application or a draft application that's been +uploaded and saved to the Android Market site. However, you must have a Google Checkout Merchant +account and the application's manifest must include the com.android.vending.BILLING +permission. If an application's manifest does not include this permission, you will be able to edit +existing items in the product list but you will not be able to add new items to the list. For more +information, see Modifying your application's AndroidManifest.xml +file.

To create a product list for an application, follow these steps:

  1. Log in to your publisher account.
  2. -
  3. In the All Android Market listings panel, under the application name, click In-app Products.
  4. +
  5. In the All Android Market listings panel, under the application name, click + In-app Products.
  6. On the In-app Products List page, click Add in-app product.
  7. -
  8. On the Create New In-app Product page (see figure 3), provide details about the item you are selling and then click Save.
  9. +
  10. On the Create New In-app Product page (see figure 3), provide details about the item you are + selling and then click Save.

- fFigure 3. The Create New In-app Product page lets you add items to an application's product list. + fFigure 3. The Create New In-app Product page lets you add items to an + application's product list.

You must enter the following information for each item in a product list:

-

For more information about product IDs and product lists, see Creating In-App Product IDs. For more information about pricing, see In-App Billing Pricing.

+

For more information about product IDs and product lists, see Creating In-App Product +IDs. For more information about pricing, see In-App Billing +Pricing.

-

Note: Be sure to plan your product ID namespace. You cannot reuse or modify product IDs after you save them.

+

Note: Be sure to plan your product ID namespace. You cannot reuse +or modify product IDs after you save them.

Choosing a Purchase Type

-

An item's purchase type controls how Android Market manages the purchase of the item. There are two purchase types: "managed per user account" and "unmanaged."

+

An item's purchase type controls how Android Market manages the purchase of the item. There are +two purchase types: "managed per user account" and "unmanaged."

-

Items that are managed per user account can be purchased only once per user account. When an item is managed per user account, Android Market permanently stores the transaction information for each item on a per-user basis. This enables you to query Android Market with the RESTORE_TRANSACTIONS request and restore the state of the items a specific user has purchased.

+

Items that are managed per user account can be purchased only once per user account. When an item +is managed per user account, Android Market permanently stores the transaction information for each +item on a per-user basis. This enables you to query Android Market with the +RESTORE_TRANSACTIONS request and restore the state of the items a specific user has +purchased.

-

If a user attempts to purchase a managed item that has already been purchased, Android Market displays an "Item already purchased" error. This occurs during checkout, when Android Market displays the price and description information on the checkout page. When the user dismisses the error message, the checkout page disappears and the user returns to your user interface. As a best practice, your application should prevent the user from seeing this error. The sample application demonstrates how you can do this by keeping track of items that are managed and already purchased and not allowing users to select those items from the list. Your application should do something similar—either graying out the item or hiding it so that it cannot be selected.

+

If a user attempts to purchase a managed item that has already been purchased, Android Market +displays an "Item already purchased" error. This occurs during checkout, when Android Market +displays the price and description information on the checkout page. When the user dismisses the +error message, the checkout page disappears and the user returns to your user interface. As a best +practice, your application should prevent the user from seeing this error. The sample application +demonstrates how you can do this by keeping track of items that are managed and already purchased +and not allowing users to select those items from the list. Your application should do something +similar—either graying out the item or hiding it so that it cannot be selected.

-

The "manage by user account" purchase type is useful if you are selling items such as game levels or application features. These items are not transient and usually need to be restored whenever a user reinstalls your application, wipes the data on their device, or installs your application on a new device.

+

The "manage by user account" purchase type is useful if you are selling items such as game levels +or application features. These items are not transient and usually need to be restored whenever a +user reinstalls your application, wipes the data on their device, or installs your application on a +new device.

-

Items that are unmanaged do not have their transaction information stored on Android Market, which means you cannot query Android Market to retrieve transaction information for items whose purchase type is listed as unmanaged. You are responsible for managing the transaction information of unmanaged items. Also, unmanaged items can be purchased multiple times as far as Android Market is concerned, so it's also up to you to control how many times an unmanaged item can be purchased.

+

Items that are unmanaged do not have their transaction information stored on Android Market, +which means you cannot query Android Market to retrieve transaction information for items whose +purchase type is listed as unmanaged. You are responsible for managing the transaction information +of unmanaged items. Also, unmanaged items can be purchased multiple times as far as Android Market +is concerned, so it's also up to you to control how many times an unmanaged item can be +purchased.

-

The "unmanaged" purchase type is useful if you are selling consumable items, such as fuel or magic spells. These items are consumed within your application and are usually purchased multiple times.

+

The "unmanaged" purchase type is useful if you are selling consumable items, such as fuel or +magic spells. These items are consumed within your application and are usually purchased multiple +times.

Handling Refunds

-

In-app billing does not allow users to send a refund request to Android Market. Refunds for in-app purchases must be directed to you (the application developer). You can then process the refund through your Google Checkout Merchant account. When you do this, Android Market receives a refund notification from Google Checkout, and Android Market sends a refund message to your application. For more information, see Handling IN_APP_NOTIFY messages and In-app Billing Pricing.

+

In-app billing does not allow users to send a refund request to Android Market. Refunds for +in-app purchases must be directed to you (the application developer). You can then process the +refund through your Google Checkout Merchant account. When you do this, Android Market receives a +refund notification from Google Checkout, and Android Market sends a refund message to your +application. For more information, see Handling +IN_APP_NOTIFY messages and In-app Billing +Pricing.

Setting Up Test Accounts

-

The Android Market publisher site lets you set up one or more test accounts. A test account is a regular Google account that you register on the publisher site as a test account. Test accounts are authorized to make in-app purchases from applications that you have uploaded to the Android Market site but have not yet published.

+

The Android Market publisher site lets you set up one or more test accounts. A test account is a +regular Google account that you register on the publisher site as a test account. Test accounts are +authorized to make in-app purchases from applications that you have uploaded to the Android Market +site but have not yet published.

-

You can use any Google account as a test account. Test accounts are useful if you want to let multiple people test in-app billing on applications without giving them access to your publisher account's sign-in credentials. If you want to own and control the test accounts, you can create the accounts yourself and distribute the credentials to your developers or testers.

+

You can use any Google account as a test account. Test accounts are useful if you want to let +multiple people test in-app billing on applications without giving them access to your publisher +account's sign-in credentials. If you want to own and control the test accounts, you can create the +accounts yourself and distribute the credentials to your developers or testers.

Test accounts have three limitations:

To add test accounts to your publisher account, follow these steps:

@@ -134,21 +230,27 @@ parent.link=index.html
  1. Log in to your publisher account.
  2. On the upper left part of the page, under your name, click Edit profile.
  3. -
  4. On the Edit Profile page, scroll down to the Licensing & In-app Billing panel (see figure 4).
  5. -
  6. In Test Accounts, add the email addresses for the test accounts you want to register, separating each account with a comma.
  7. +
  8. On the Edit Profile page, scroll down to the Licensing & In-app Billing panel (see figure + 4).
  9. +
  10. In Test Accounts, add the email addresses for the test accounts you want to register, + separating each account with a comma.
  11. Click Save to save your profile changes.

- Figure 4. The Licensing and In-app Billing panel of your account's Edit Profile page lets you register test accounts. + Figure 4. The Licensing and In-app Billing panel of your account's Edit Profile + page lets you register test accounts.

Where to Get Support

-

If you have questions or encounter problems while implementing in-app billing, contact the support resources listed in the following table (see table 2). By directing your queries to the correct forum, you can get the support you need more quickly.

+

If you have questions or encounter problems while implementing in-app billing, contact the +support resources listed in the following table (see table 2). By directing your queries to the +correct forum, you can get the support you need more quickly.

-

Table 2. Developer support resources for Android Market in-app billing.

+

Table 2. Developer support resources +for Android Market in-app billing.

@@ -159,12 +261,15 @@ parent.link=index.html - - + + +href="http://stackoverflow.com/questions/tagged/android">http://stackoverflow.com/questions/tagged/ +android @@ -174,7 +279,9 @@ project issue tracker
Development and testing issuesGoogle Groups: android-developers In-app billing integration questions, user experience ideas, handling of responses, obfuscating code, IPC, test environment setup.Google Groups: android-developers In-app billing integration questions, user experience ideas, handling of responses, +obfuscating code, IPC, test environment setup.
Stack Overflow: http://stackoverflow.com/questions/tagged/android
Market billing issue tracker
-

For general information about how to post to the groups listed above, see Developer Forums document in the Resources tab.

+

For general information about how to post to the groups listed above, see Developer Forums document in the Resources +tab.

diff --git a/docs/html/guide/market/billing/billing_best_practices.jd b/docs/html/guide/market/billing/billing_best_practices.jd index 6f9f64c286534..d9776af5e9c76 100755 --- a/docs/html/guide/market/billing/billing_best_practices.jd +++ b/docs/html/guide/market/billing/billing_best_practices.jd @@ -11,62 +11,101 @@ parent.link=index.html

Downloads

    -
  1. Sample Application
  2. +
  3. Sample + Application

See also

    -
  1. Overview of In-app Billing
  2. -
  3. Implementing In-app Billing
  4. -
  5. Testing In-app Billing
  6. -
  7. Administering In-app Billing
  8. -
  9. In-app Billing Reference
  10. +
  11. Overview of In-app + Billing
  12. +
  13. Implementing In-app + Billing
  14. +
  15. Testing In-app + Billing
  16. +
  17. Administering In-app + Billing
  18. +
  19. In-app Billing + Reference
-

As you design your in-app billing implementation, be sure to follow the security and design guidelines that are discussed in this document. These guidelines are recommended best practices for anyone who is using Android Market's in-app billing service.

+

As you design your in-app billing implementation, be sure to follow the security and design +guidelines that are discussed in this document. These guidelines are recommended best practices for +anyone who is using Android Market's in-app billing service.

Security Best Practices

Perform signature verification tasks on a server

-

If practical, you should perform signature verification on a remote server and not on a device. Implementing the verification process on a server makes it difficult for attackers to break the verification process by reverse engineering your .apk file. If you do offload security processing to a remote server, be sure that the device-server handshake is secure.

+

If practical, you should perform signature verification on a remote server and not on a device. +Implementing the verification process on a server makes it difficult for attackers to break the +verification process by reverse engineering your .apk file. If you do offload security processing to +a remote server, be sure that the device-server handshake is secure.

Protect your unlocked content

-

To prevent malicious users from redistributing your unlocked content, do not bundle it in your .apk file. Instead, do one of the following:

+

To prevent malicious users from redistributing your unlocked content, do not bundle it in your +.apk file. Instead, do one of the following:

-

When you deliver content from a remote server or a real-time service, you can store the unlocked content in device memory or store it on the device's SD card. If you store content on an SD card, be sure to encrypt the content and use a device-specific encryption key.

+

When you deliver content from a remote server or a real-time service, you can store the unlocked +content in device memory or store it on the device's SD card. If you store content on an SD card, be +sure to encrypt the content and use a device-specific encryption key.

Obfuscate your code

-

You should obfuscate your in-app billing code so it is difficult for an attacker to reverse engineer security protocols and other application components. At a minimum, we recommend that you run an obfuscation tool like Proguard on your code.

-

In addition to running an obfuscation program, we recommend that you use the following techniques to obfuscate your in-app billing code.

+

You should obfuscate your in-app billing code so it is difficult for an attacker to reverse +engineer security protocols and other application components. At a minimum, we recommend that you +run an obfuscation tool like Proguard on your +code.

+

In addition to running an obfuscation program, we recommend that you use the following techniques +to obfuscate your in-app billing code.

-

Using these techniques can help reduce the attack surface of your application and help minimize attacks that can compromise your in-app billing implementation.

+

Using these techniques can help reduce the attack surface of your application and help minimize +attacks that can compromise your in-app billing implementation.

-

Note: If you use Proguard to obfuscate your code, you must add the following line to your Proguard configuration file:

+

Note: If you use Proguard to obfuscate your code, you must add the following + line to your Proguard configuration file:

-keep class com.android.vending.billing.**

Modify all sample application code

-

The in-app billing sample application is publicly distributed and can be downloaded by anyone, which means it is relatively easy for an attacker to reverse engineer your application if you use the sample code exactly as it is published. The sample application is intended to be used only as an example. If you use any part of the sample application, you must modify it before you publish it or release it as part of a production application.

-

In particular, attackers look for known entry points and exit points in an application, so it is important that you modify these parts of your code that are identical to the sample application.

+

The in-app billing sample application is publicly distributed and can be downloaded by anyone, +which means it is relatively easy for an attacker to reverse engineer your application if you use +the sample code exactly as it is published. The sample application is intended to be used only as an +example. If you use any part of the sample application, you must modify it before you publish it or +release it as part of a production application.

+

In particular, attackers look for known entry points and exit points in an application, so it is +important that you modify these parts of your code that are identical to the sample application.

Use secure random nonces

-

Nonces must not be predictable or reused. Always use a cryptographically secure random number generator (like {@link java.security.SecureRandom}) when you generate nonces. This can help reduce replay attacks.

-

Also, if you are performing nonce verification on a server, make sure that you generate the nonces on the server.

+

Nonces must not be predictable or reused. Always use a cryptographically secure random number +generator (like {@link java.security.SecureRandom}) when you generate nonces. This can help reduce +replay attacks.

+

Also, if you are performing nonce verification on a server, make sure that you generate the +nonces on the server.

Take action against trademark and copyright infringement

-

If you see your content being redistributed on Android Market, act quickly and decisively. File a trademark notice of infringement or a copyright notice of infringement.

+

If you see your content being redistributed on Android Market, act quickly and decisively. File a +trademark notice +of infringement or a copyright notice of +infringement.

Implement a revocability scheme for unlocked content

-

If you are using a remote server to deliver or manage content, have your application verify the purchase state of the unlocked content whenever a user accesses the content. This allows you to revoke use when necessary and minimize piracy.

+

If you are using a remote server to deliver or manage content, have your application verify the +purchase state of the unlocked content whenever a user accesses the content. This allows you to +revoke use when necessary and minimize piracy.

Protect your Android Market public key

-

To keep your public key safe from malicious users and hackers, do not embed it in any code as a literal string. Instead, construct the string at runtime from pieces or use bit manipulation (for example, XOR with some other string) to hide the actual key. The key itself is not secret information, but you do not want to make it easy for a hacker or malicious user to replace the public key with another key.

+

To keep your public key safe from malicious users and hackers, do not embed it in any code as a +literal string. Instead, construct the string at runtime from pieces or use bit manipulation (for +example, XOR with some other string) to hide the actual key. The key itself is not secret +information, but you do not want to make it easy for a hacker or malicious user to replace the +public key with another key.

diff --git a/docs/html/guide/market/billing/billing_integrate.jd b/docs/html/guide/market/billing/billing_integrate.jd index 75323378923a0..f57ebe374dd4e 100755 --- a/docs/html/guide/market/billing/billing_integrate.jd +++ b/docs/html/guide/market/billing/billing_integrate.jd @@ -21,33 +21,50 @@ parent.link=index.html

See also

    -
  1. Overview of In-app Billing
  2. -
  3. Security and Design
  4. -
  5. Testing In-app Billing
  6. -
  7. Administering In-app Billing
  8. -
  9. In-app Billing Reference
  10. +
  11. Overview of In-app + Billing
  12. +
  13. Security and + Design
  14. +
  15. Testing In-app + Billing
  16. +
  17. Administering In-app + Billing
  18. +
  19. In-app Billing + Reference
-

Android Market In-app Billing provides a straightforward, simple interface for sending in-app billing requests and managing in-app billing transactions using Android Market. This document helps you implement in-app billing by stepping through the primary implementation tasks, using the in-app billing sample application as an example.

+

Android Market In-app Billing provides a straightforward, simple interface for sending in-app +billing requests and managing in-app billing transactions using Android Market. This document helps +you implement in-app billing by stepping through the primary implementation tasks, using the in-app +billing sample application as an example.

-

Before you implement in-app billing in your own application, be sure that you read Overview of In-app Billing and Security and Design. These documents provide background information that will make it easier for you to implement in-app billing.

+

Before you implement in-app billing in your own application, be sure that you read Overview of In-app Billing and Security and Design. These +documents provide background information that will make it easier for you to implement in-app +billing.

To implement in-app billing in your application, you need to do the following:

  1. Download the in-app billing sample application.
  2. Add the IMarketBillingService.aidl file to your project.
  3. Update your AndroidManifest.xml file.
  4. -
  5. Create a Service and bind it to the MarketBillingService so your application can send billing requests and receive billing responses from the Android Market application.
  6. -
  7. Create a BroadcastReceiver to handle broadcast intents from the Android Market application.
  8. -
  9. Create a security processing component to verify the integrity of the transaction messages that are sent by Android Market .
  10. +
  11. Create a Service and bind it to the + MarketBillingService so your application can send billing requests and receive + billing responses from the Android Market application.
  12. +
  13. Create a BroadcastReceiver to handle broadcast + intents from the Android Market application.
  14. +
  15. Create a security processing component to verify the + integrity of the transaction messages that are sent by Android Market .
  16. Modify your application code to support in-app billing.

Downloading the Sample Application

-

The in-app billing sample application shows you how to perform several tasks that are common to all Android Market in-app billing implementations, including:

+

The in-app billing sample application shows you how to perform several tasks that are common to +all Android Market in-app billing implementations, including:

-

The sample application includes an application file (Dungeons.java), the AIDL file for the MarketBillingService (IMarketBillingService.aidl), and several classes that demonstrate in-app billing messaging. It also includes a class that demonstrates basic security tasks, such as signature verification.

+

The sample application includes an application file (Dungeons.java), the AIDL file +for the MarketBillingService (IMarketBillingService.aidl), and several +classes that demonstrate in-app billing messaging. It also includes a class that demonstrates basic +security tasks, such as signature verification.

Table 1 lists the source files that are included with the sample application.

-

Table 1. In-app billing sample application source files.

+

Table 1. In-app billing sample +application source files.

@@ -70,12 +91,14 @@ parent.link=index.html - + - + @@ -85,16 +108,20 @@ parent.link=index.html - + - + - + @@ -109,29 +136,38 @@ parent.link=index.html - + - +
IMarketBillingService.aidlAndroid Interface Definition Library (AIDL) file that defines the IPC interface to Android Market's in-app billing service (MarketBillingService).Android Interface Definition Library (AIDL) file that defines the IPC interface to Android +Market's in-app billing service (MarketBillingService).
Dungeons.javaSample application file that provides a UI for making purchases and displaying purchase history.Sample application file that provides a UI for making purchases and displaying purchase +history.
BillingReceiver.javaA {@link android.content.BroadcastReceiver} that receives asynchronous response messages (broadcast intents) from Android Market. Forwards all messages to the BillingService.A {@link android.content.BroadcastReceiver} that receives asynchronous response messages + (broadcast intents) from Android Market. Forwards all messages to the + BillingService.
BillingService.javaA {@link android.app.Service} that sends messages to Android Market on behalf of the application by connecting (binding) to the MarketBillingService.A {@link android.app.Service} that sends messages to Android Market on behalf of the + application by connecting (binding) to the MarketBillingService.
ResponseHandler.javaA {@link android.os.Handler} that contains methods for updating the purchases database and the UI.A {@link android.os.Handler} that contains methods for updating the purchases database and the + UI.
Consts.javaDefines various Android Market constants and sample application constants. All constants that are defined by Android Market must be defined the same way in your application.Defines various Android Market constants and sample application constants. All constants that +are defined by Android Market must be defined the same way in your application.
Base64.java and Base64DecoderException.javaProvides conversion services from binary to Base64 encoding. The Security class relies on these utility classes.Provides conversion services from binary to Base64 encoding. The Security class +relies on these utility classes.
-

The in-app billing sample application is available as a downloadable component of the Android SDK. To download the sample application component, launch the Android SDK and AVD Manager and then select the "Google Market Billing package" component (see figure 1), and click Install Selected to begin the download.

+

The in-app billing sample application is available as a downloadable component of the Android +SDK. To download the sample application component, launch the Android SDK and AVD Manager and then +select the "Google Market Billing package" component (see figure 1), and click Install +Selected to begin the download.

- Figure 1. The Google Market Billing package contains the sample application and the AIDL file. + Figure 1. The Google Market Billing package contains the sample application and + the AIDL file.

-

When the download is complete, the Android SDK and AVD Manager saves the component into the following directory:

+

When the download is complete, the Android SDK and AVD Manager saves the component into the +following directory:

<sdk>/google-market_billing/

-

If you want to see an end-to-end demonstration of in-app billing before you integrate in-app billing into your own application, you can build and run the sample application. Building and running the sample application involves three tasks:

+

If you want to see an end-to-end demonstration of in-app billing before you integrate in-app +billing into your own application, you can build and run the sample application. Building and +running the sample application involves three tasks:

-

Note: Building and running the sample application is necessary only if you want to see a demonstration of in-app billing. If you do not want to run the sample application, you can skip to the next section, Adding the AIDL file to your project.

+

Note: Building and running the sample application is necessary only +if you want to see a demonstration of in-app billing. If you do not want to run the sample +application, you can skip to the next section, Adding the AIDL file to +your project.

Configuring and building the sample application

-

Before you can run the sample application, you need to configure it and build it by doing the following:

+

Before you can run the sample application, you need to configure it and build it by doing the +following:

  1. Add your Android Market public key to the sample application code. -

    This enables the application to verify the signature of the transaction information that is returned from Android Market. To add your public key to the sample application code, do the following:

    +

    This enables the application to verify the signature of the transaction information that is + returned from Android Market. To add your public key to the sample application code, do the + following:

      -
    1. Log in to your Android Market publisher account.
    2. -
    3. On the upper left part of the page, under your name, click Edit Profile.
    4. -
    5. On the Edit Profile page, scroll down to the Licensing & In-app Billing panel.
    6. +
    7. Log in to your Android Market publisher + account.
    8. +
    9. On the upper left part of the page, under your name, click Edit + Profile.
    10. +
    11. On the Edit Profile page, scroll down to the Licensing & In-app + Billing panel.
    12. Copy your public key.
    13. Open src/com/example/dungeons/Security.java in the editor of your choice.

      You can find this file in the sample application's project folder.

      @@ -163,61 +208,112 @@ parent.link=index.html
  2. Change the package name of the sample application. -

    The current package name is com.example.dungeons. Android Market does not let you upload applications with package names that contain com.example, so you must change the package name to something else.

    +

    The current package name is com.example.dungeons. Android Market does not let + you upload applications with package names that contain com.example, so you must + change the package name to something else.

  3. Build the sample application in release mode and sign it. -

    To learn how to build and sign applications, see Building and Running.

    +

    To learn how to build and sign applications, see Building and Running.

Uploading the sample application

-

After you build a release version of the sample application and sign it, you need to upload it as a draft to the Android Market publisher site. You also need to create a product list for the in-app items that are available for purchase in the sample application. The following instructions show you how to do this.

+

After you build a release version of the sample application and sign it, you need to upload it as +a draft to the Android Market publisher site. You also need to create a product list for the in-app +items that are available for purchase in the sample application. The following instructions show you +how to do this.

  1. Upload the release version of the sample application to Android Market. -

    Do not publish the sample application; leave it as an unpublished draft application. The sample application is for demonstration purposes only and should not be made publicly available on Android Market. To learn how to upload an application to Android Market, see Uploading applications.

    +

    Do not publish the sample application; leave it as an unpublished draft application. The + sample application is for demonstration purposes only and should not be made publicly available + on Android Market. To learn how to upload an application to Android Market, see Uploading + applications.

  2. Create a product list for the sample application. -

    The sample application lets you purchase two items: a two-handed sword (sword_001) and a potion (potion_001). We recommend that you set up your product list so that sword_001 has a purchase type of "Managed per user account" and potion_001 has a purchase type of "Unmanaged" so you can see how these two purchase types behave. To learn how to set up a product list, see Creating a Product List.

    -

    Note: You must publish the items in your product list (sword_001 and potion_001) even though you are not publishing the sample application. Also, you must have a Google Checkout Merchant account to add items to the sample application's product list.

    +

    The sample application lets you purchase two items: a two-handed sword + (sword_001) and a potion (potion_001). We recommend that you set up + your product list so that sword_001 has a purchase type of "Managed per user + account" and potion_001 has a purchase type of "Unmanaged" so you can see how these + two purchase types behave. To learn how to set up a product list, see Creating a Product + List.

    +

    Note: You must publish the items in your product + list (sword_001 and potion_001) even though you are not publishing the + sample application. Also, you must have a Google Checkout Merchant account to add items to the + sample application's product list.

Running the sample application

-

You cannot run the sample application in the emulator. You must install the sample application onto a device to run it. To run the sample application, do the following:

+

You cannot run the sample application in the emulator. You must install the sample application +onto a device to run it. To run the sample application, do the following:

    -
  1. Make sure you have at least one test account registered under your Android Market publisher account. -

    You cannot purchase items from yourself (Google Checkout prohibits this), so you need to create at least one test account that you can use to purchase items in the sample application. To learn how to set up a test account, see Setting up Test Accounts.

    +
  2. Make sure you have at least one test account registered under your Android Market + publisher account. +

    You cannot purchase items from yourself (Google Checkout prohibits this), so you need to + create at least one test account that you can use to purchase items in the sample application. + To learn how to set up a test account, see Setting up Test + Accounts.

  3. -
  4. Verify that your device is running a supported version of the Android Market application or the MyApps application. -

    If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see Updating Android Market.

    +
  5. Verify that your device is running a supported version of the Android Market + application or the MyApps application. +

    If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of + the MyApps application. If your device is running any other version of Android, in-app billing + requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the + version of the Android Market application, see Updating Android + Market.

  6. Install the application onto your device. -

    Even though you uploaded the application to Android Market, the application is not published, so you cannot download it from Android Market to a device. Instead, you must install the application onto your device. To learn how to install an application onto a device, see Running on a device.

    +

    Even though you uploaded the application to Android Market, the application is not published, + so you cannot download it from Android Market to a device. Instead, you must install the + application onto your device. To learn how to install an application onto a device, see Running on a + device.

  7. Make one of your test accounts the primary account on your device. -

    The primary account on your device must be one of the test accounts that you registered on the Android Market site. If the primary account on your device is not a test account, you must do a factory reset of the device and then sign in with one of your test accounts. To perform a factory reset, do the following:

    +

    The primary account on your device must be one of the test accounts + that you registered on the Android Market site. If the primary account on your device is not a + test account, you must do a factory reset of the device and then sign in with one of your test + accounts. To perform a factory reset, do the following:

    1. Open Settings on your device.
    2. Touch Privacy.
    3. Touch Factory data reset.
    4. Touch Reset phone.
    5. -
    6. After the phone resets, be sure to sign in with one of your test accounts during the device setup process.
    7. +
    8. After the phone resets, be sure to sign in with one of your test accounts during the + device setup process.
  8. Run the application and purchase the sword or the potion. -

    When you use a test account to purchase items, the test account is billed through Google Checkout and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may want to refund purchases that are made with test accounts, otherwise the purchases will show up as actual payouts to your merchant account.

    +

    When you use a test account to purchase items, the test account is billed through Google + Checkout and your Google Checkout Merchant account receives a payout for the purchase. + Therefore, you may want to refund purchases that are made with test accounts, otherwise the + purchases will show up as actual payouts to your merchant account.

Note: Debug log messages are turned off by default in the sample application. You can turn them on by setting the variable DEBUG to true in the Consts.java file.

Adding the AIDL file to your project

-

The sample application contains an Android Interface Definition Language (AIDL) file, which defines the interface to Android Market's in-app billing service (MarketBillingService). When you add this file to your project, the Android build environment creates an interface file (IMarketBillingService.java). You can then use this interface to make billing requests by invoking IPC method calls.

+

The sample application contains an Android Interface Definition Language (AIDL) file, which +defines the interface to Android Market's in-app billing service +(MarketBillingService). When you add this file to your project, the Android build +environment creates an interface file (IMarketBillingService.java). You can then use +this interface to make billing requests by invoking IPC method calls.

-

If you are using the ADT plug-in with Eclipse, you can just add this file to your /src directory. Eclipse will automatically generate the interface file when you build your project (which should happen immediately). If you are not using the ADT plug-in, you can put the AIDL file into your project and use the Ant tool to build your project so that the IMarketBillingService.java file gets generated.

+

If you are using the ADT plug-in with Eclipse, you can just add this file to your +/src directory. Eclipse will automatically generate the interface file when you build +your project (which should happen immediately). If you are not using the ADT plug-in, you can put +the AIDL file into your project and use the Ant tool to build your project so that the +IMarketBillingService.java file gets generated.

To add the IMarketBillingService.aidl file to your project, do the following:

@@ -225,19 +321,39 @@ parent.link=index.html
  • Create the following directory in your application's /src directory:

    com/android/vending/billing/

  • -
  • Copy the IMarketBillingService.aidl file into the sample/src/com/android/vending/billing/ directory.
  • +
  • Copy the IMarketBillingService.aidl file into the + sample/src/com/android/vending/billing/ directory.
  • Build your application.
  • -

    You should now find a generated interface file named IMarketBillingService.java in the gen folder of your project.

    +

    You should now find a generated interface file named IMarketBillingService.java in +the gen folder of your project.

    Updating Your Application's Manifest

    -

    In-app billing relies on the Android Market application, which handles all communication between your application and the Android Market server. To use the Android Market application, your application must request the proper permission. You can do this by adding the com.android.vending.BILLING permission to your AndroidManifest.xml file. If your application does not declare the in-app billing permission, but attempts to send billing requests, Android Market will refuse the requests and respond with a RESULT_DEVELOPER_ERROR response code.

    +

    In-app billing relies on the Android Market application, which handles all communication between +your application and the Android Market server. To use the Android Market application, your +application must request the proper permission. You can do this by adding the +com.android.vending.BILLING permission to your AndroidManifest.xml file. If your +application does not declare the in-app billing permission, but attempts to send billing requests, +Android Market will refuse the requests and respond with a RESULT_DEVELOPER_ERROR +response code.

    -

    In addition to the billing permission, you need to declare the {@link android.content.BroadcastReceiver} that you will use to receive asynchronous response messages (broadcast intents) from Android Market, and you need to declare the {@link android.app.Service} that you will use to bind with the IMarketBillingService and send messages to Android Market. You must also declare intent filters for the {@link android.content.BroadcastReceiver} so that the Android system knows how to handle the broadcast intents that are sent from the Android Market application.

    +

    In addition to the billing permission, you need to declare the {@link +android.content.BroadcastReceiver} that you will use to receive asynchronous response messages +(broadcast intents) from Android Market, and you need to declare the {@link android.app.Service} +that you will use to bind with the IMarketBillingService and send messages to Android +Market. You must also declare intent filters for the {@link +android.content.BroadcastReceiver} so that the Android system knows how to handle the broadcast +intents that are sent from the Android Market application.

    -

    For example, here is how the in-app billing sample application declares the billing permission, the {@link android.content.BroadcastReceiver}, the {@link android.app.Service}, and the intent filters. In the sample application, BillingReceiver is the {@link android.content.BroadcastReceiver} that handles broadcast intents from the Android Market application and BillingService is the {@link android.app.Service} that sends requests to the Android Market application.

    +

    For example, here is how the in-app billing sample application declares the billing permission, +the {@link android.content.BroadcastReceiver}, the {@link android.app.Service}, and the intent +filters. In the sample application, BillingReceiver is the {@link +android.content.BroadcastReceiver} that handles broadcast intents from the Android Market +application and BillingService is the {@link android.app.Service} that sends requests +to the Android Market application.

     <?xml version="1.0" encoding="utf-8"?>
    @@ -272,11 +388,13 @@ parent.link=index.html
     
     

    Creating a Local Service

    -

    Your application must have a local {@link android.app.Service} to facilitate messaging between your application and Android Market. At a minimum, this service must do the following:

    +

    Your application must have a local {@link android.app.Service} to facilitate messaging between +your application and Android Market. At a minimum, this service must do the following: