From d126294a8f954fb758d3f67bc5271014748ba9e7 Mon Sep 17 00:00:00 2001 From: Eric Gilmore Date: Fri, 10 Oct 2014 14:24:11 -0700 Subject: [PATCH] Docs: Adding Android Studio instructions for adding IAB service. Incorporating some editorial feedback both in and outside the scope of my small bug fix. Bug: 17151052 Change-Id: Id3b0c256ca6f7f018fa525eeb1f78979e8f476df --- .../training/in-app-billing/preparing-iab-app.jd | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/html/training/in-app-billing/preparing-iab-app.jd b/docs/html/training/in-app-billing/preparing-iab-app.jd index 47fcbbddb12ed..344693a57fe5f 100644 --- a/docs/html/training/in-app-billing/preparing-iab-app.jd +++ b/docs/html/training/in-app-billing/preparing-iab-app.jd @@ -78,14 +78,16 @@ next.link=list-iab-products.html
  1. Copy the {@code IInAppBillingService.aidl} file to your Android project.
      -
    • If you are using Eclipse: Import the {@code IInAppBillingService.aidl} file into your {@code /src} directory.
    • -
    • If you are developing in a non-Eclipse environment: Create the following directory {@code /src/com/android/vending/billing} and copy the {@code IInAppBillingService.aidl} file into this directory.
    • +
    • In Android Studio: Create a directory named {@code aidl} under {@code src/main}, add a new + package {@code com.android.vending.billing} in this directory, and import the + {@code IInAppBillingService.aidl} file into this package.
    • +
    • In Eclipse: Import the {@code IInAppBillingService.aidl} file into your {@code /src} directory.
    • +
    • In other dev environments: Create the following directory {@code /src/com/android/vending/billing} and copy the {@code IInAppBillingService.aidl} file into this directory.
  2. Build your application. You should see a generated file named {@code IInAppBillingService.java} in the {@code /gen} directory of your project.
  3. Add the helper classes from the {@code /util} directory of the {@code TrivialDrive} sample to your project. Remember to change the package name declarations in those files accordingly so that your project compiles correctly.
-

Your project should now contain the In-app Billing Version 3 library.

Set the Billing Permission

@@ -106,7 +108,7 @@ IabHelper mHelper; public void onCreate(Bundle savedInstanceState) { // ... String base64EncodedPublicKey; - + // compute your public key and store it in base64EncodedPublicKey mHelper = new IabHelper(this, base64EncodedPublicKey); } @@ -120,15 +122,15 @@ mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { if (!result.isSuccess()) { // Oh noes, there was a problem. Log.d(TAG, "Problem setting up In-app Billing: " + result); - } - // Hooray, IAB is fully set up! + } + // Hooray, IAB is fully set up! } });

If the setup completed successfully, you can now use the {@code mHelper} reference to communicate with the Google Play service. When your application is launched, it is a good practice to query Google Play to find out what in-app items are owned by a user. This is covered further in the Query Purchased Items section.

-

Important: Remember to unbind from the In-app Billing service when you are done with your activity. If you don’t unbind, the open service connection could cause your device’s performance to degrade. To unbind and free your system resources, call the {@code IabHelper}'s {@code dispose} method when your {@code Activity} gets destroyed.

+

Important: Remember to unbind from the In-app Billing service when you are done with your activity. If you don’t unbind, the open service connection could cause your device’s performance to degrade. To unbind and free your system resources, call the {@code IabHelper}'s {@code dispose} method when your {@code Activity} is destroyed.

 @Override