Skip to main content
Samsung Developer Program

IAP Android App Sample Project

Example app code that demonstrates Samsung IAP features and integration.

 

The IAPSample app is a straightforward shoot 'em up app that demonstrates the integration of all Samsung IAP functions and in-app item types.

  • The sample app:
    • Initiates Samsung IAP Client, based on getInstance().
    • Displays:
      • Descriptions of all in-app items, based on getProductDetails().
      • The current type of gun, based on the nonconsumable items returned by getOwnedList().
      • The current number of available bullets out of the maximum number (# / 5).
         
    • Enables users to:
      • Use the default type of gun or purchase another type.
      • Shoot one bullet at time.
      • Purchase all types of Samsung IAP items, based on startPurchase():
        • A consumable item (one bullet).
        • A nonconsumable item (a type of gun)
        • An (an endless supply of bullets)
           
  • Samsung IAP manages purchase transactions.
  • After purchasing a consumable item, the app immediately reports the item as consumed, based on consumePurchasedItems().

 

To build and run the sample app

  • Set up your Android Studio development environment.
    For details, see Android Studio IDE Setup.
  • Download the Samsung IAP sample project code, which is part of the Samsung IAP SDK (https://developer.samsung.com/iap#).
  • Unzip the sample project code into a local folder (for example, SamsungIAP).

 

  1. In Android Studio, build the sample app:
    1. Select Open an existing Android Stuio project and choose the SamsungIAP folder.
    2. In the root directory, edit the build.gradle by replacing all of it with:
      // Top-level build file where you can add configuration options common to all sub-projects/modules. 
      buildscript { 
          repositories { 
              jcenter () 
          } 
          dependencies { 
              classpath 'com.android.tools.build:gradle:2.3.1' 
          } 
      } 
      
      allprojects { 
          repositories { 
              jcenter () 
          } 
      }
    3. Edit the IAP5Helper\build.gradle by changing buildToolsVersion to 25.0.0 

    4. Edit the IAP5Sample\build.gradle by changing buildToolsVersion to 25.0.0 

    5. Edit the MainActivity.java by changing IAP_MODE to:

      private static OperationMode IAP_MODE = OperationMode.OPERATION_MODE_TEST;
      
  2. In Android Studio, run the sample app:

    1. Select Run > Run IAPSample.

      IAP_SampleProject_MainScreen.jpg
       

    2. Select the app options:

      1. ... (top right corner) - Displays descriptions of all in-app items

      2. Shot - Shoots a bullet.

      3. Get a bullet - Initiates the purchase of one bullet (a consumable item).

      4. Upgrade the gun - Initiates the purchase of and displays the optional type of gun (a non consumable item).

      5. Get infinite bullets - Initiates the purchase of an endless supply of bullets (a subscription item).
         

    3. After selecting a purchase option, Samsung IAP manages the purchase:

      IAP_SampleProject_ItemPurchaseScreen.jpg
       

      1. The 'Sandbox' logo displayed in the upper left corner indicates that Samsung IAP is in one of the developer test modes and that the user will not be charged.

      2. A payment method can be selected, but is not used.

      3. Points and coupon codes can be added, but are not applied.

      4. To complete the purchase transaction, click Buy.
         

    4. Review the app UI to see the results of option selections :

      1. Shot - Reduces the available bullet count by one.

      2. Get a bullet - Increases the available bullet count by one.

      3. Upgrade the gun - Displays the image of the optional type of gun.

      4. Get infinite bullets - Permanently maintains the maximum number of available bullets (5).

 

 

 

  • Was this article helpful?