Skip to main content
Samsung Developer Program

Purchase Nonconsumable Items

The Premium Car feature of this application is a nonconsumable item. This means that this item can be purchased only once. The premium car does not expire and can be reused an unlimited number of times. 

  1. In the Trivial Drive UI, click UPGRADE MY CAR (NC).
  2. The button click invokes the function onUpgradeAppButtonClicked() of, which calls OpenIabHelper.launchPurchaseFlow(). InAppConfig.SKU_PREMIUM is specified as a parameter.
public void onUpgradeAppButtonClicked(View arg0) {
    Log.d(TAG, "Upgrade button clicked; launching purchase flow for upgrade.");
    if (setupDone == null) {
        complain("Billing Setup is not completed yet");
    if (!setupDone) {
        complain("Billing Setup failed");
    /* TO DO: For security, generate your payload here for verification. See the comments on verifyDeveloperPayload() for more
    info. Since this is a SAMPLE, we just use an empty string. But on a production app, you should carefully generate this.*/
    String payload = " ";
    mHelper.launchPurchaseFlow(this, InAppConfig.SKU_PREMIUM, RC_REQUEST, mPurchaseFinishedListener, payload);
  1. OpenIabHelper.launchPurchaseFlow() calls the launchPurchaseFlow() function of
public void launchPurchaseFlow(Activity act, @NotNull String sku, int requestCode, 
                        IabHelper.OnIabPurchaseFinishedListener listener, String extraData) {
    Logger.d("Purchase flow for INAPP Item started");
    launchPurchaseFlow(act, sku, ITEM_TYPE_INAPP, requestCode, listener, extraData);
public void launchPurchaseFlow(Activity act, @NotNull String sku, String itemType, int requestCode, 
                        IabHelper.OnIabPurchaseFinishedListener listener, String extraData) {
    appStoreBillingService.launchPurchaseFlow(act, SkuManager.getInstance().getStoreSku(appstore.getAppStoreName(), sku), 
                        itemType, requestCode, listener, extraData);
  1. AppStoreInAppBillingService.launchPurchaseFlow() is invoked, which starts the billing service for the chosen app store. For Samsung, SamsungAppsBillingService.launchPurchaseFlow() is invoked.
public void launchPurchaseFlow(@NotNull Activity activity, @NotNull String sku, String itemType, int requestCode, 
                        OnIabPurchaseFinishedListener listener, String extraData) {
    String itemGroupId = getItemGroupId(sku);
    String itemId = getItemId(sku);
    Bundle bundle = new Bundle();
    bundle.putString(KEY_NAME_THIRD_PARTY_NAME, activity.getPackageName());
    /* If 12-digit itemGroupId is specified in SKU mapping, bundle will include 
    itemGroupId. If itemGroupId is not specified, third-party package name will be used. (Samsung IAP v3.0) */
    if (!itemGroupId.isEmpty()) {
        bundle.putString(KEY_NAME_ITEM_GROUP_ID, itemGroupId);
    bundle.putString(KEY_NAME_ITEM_ID, itemId);
    Logger.d("launchPurchase: itemGroupId = ", itemGroupId, ", itemId = ", itemId);
    ComponentName cmpName = new ComponentName(SamsungApps.IAP_PACKAGE_NAME, PAYMENT_ACTIVITY_NAME);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    mRequestCode = requestCode;
    mPurchaseListener = listener;
    purchasingItemType = itemType;
    mItemGroupId = itemGroupId;
    mExtraData = extraData;
    Logger.d("Request code: ", requestCode);
    activity.startActivityForResult(intent, requestCode);
  1. After a successful purchase, the result is sent back to through the IabHelper.OnIabPurchaseFinishedListener
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinshed(IabResult result, Purchase purchase) {
        else if (purchase.getSku().equals(InAppConfig.SKU_PREMIUM)) {
                // Bought the premium upgrade!
            Log.d(TAG, "Purchase is premium upgrade. Congratulating user.");
            mIsPremium = true;