Skip to main content
Samsung Developer Program

Get Details about Offered In-App Items

How to retrieve information about one or more in-app items offered for sale by your Android app

 

Your Android app and your users can get information about one or more in-app items registered to your Android app in order to: use the retrieved item information (for example, to determine what items the user may be interested in), and to display item information (for example, in the Product details page, or to help the user select an in-app item for purchase).

The example code in the first procedure demonstrates how to: set up a UI button, hard code three in-app item IDs, instantiate an IapHelper object and submit a request to get in-app item details, set up necessary listeners, receive the request results and display item details in an offered item list or an error result message. 

For more details about the IAP Helper API elements, see:

To get information about offered in-app items:

  1. Add a UI button that calls doGetProductsDetails() to the activity_main.xml layout.
    <!-- GetProductsDetails Button --> 
    <Button 
        android:id="@+id/btn_get_products_details" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/get_products_details" 
        android:onClick="doGetProductsDetails"/>


     
  2. Add the IDs of the in-app items to the MainActivity.java file.
    private static final String ITEM_IDS = "Nuclear, Claymore, SpeedUp";
    
    


     
  3. Instantiate an IapHelper object and call getProductsDetails() to request details about the in-app items, by adding doGetProductsDetails() to the MainActivity class.pu
    blic void doGetProductsDetails(View _view) { 
        if (mIapHelper == null) { 
            mIapHelper = IapHelper.getInstance(this); 
        } 
        
        mIapHelper.getProductsDetails(ITEM_IDS, this);
    }


     
  4. After the MainActivity class declaration, implement the OnGetProductsDetailsListener interface (to get item details and processing results) and the OnPaymentListener interface (to get the purchase ID of the items).  
    public class MainActivity extends AppCompatActivity 
        implements OnPaymentListener, OnGetProductsDetailsListener {
    
    


     
  5. Process and display the getProductsDetails() results in AlertDialog by implementing the onGetProducts() callback method in the OnGetProductsDetailsListener interface.
    @Override 
    public void onGetProducts(ErrorVo _errorVO, ArrayList<ProductVo> _productList) { 
    
        AlertDialog.Builder alert = new AlertDialog.Builder(this); 
        alert.setPositiveButton(android.R.string.ok, 
                                new DialogInterface.OnClickListener() { 
        
            @Override
            public void onClick(DialogInterface dialog, int which) { 
                try { 
                     dialog.dismiss(); 
                } 
                catch (Exception e) { 
                       e.printStackTrace(); 
                } 
            } 
        ); 
                
    if (_errorVO != null) { 
        if (_errorVO.getErrorCode() == IapHelper.IAP_ERROR_NONE) { 
            alert.setTitle(R.string.products_details); 
        
            String message = ""; 
        
            for (ProductVo vo : _productList) { 
                message += vo.dump() + "\n" + 
                           "--------------------------------------" + "\n"; 
                } 
            
                alert.setMessage(message);
                 
            } 
            else { 
                alert.setTitle(R.string.products_details); 
                alert.setMessage(_errorVO.getErrorString()); 
            } 
        } 
        else { 
            alert.setTitle(R.string.products_details); 
            alert.setMessage("ErrorVo is null"); 
        } 
        
        try { 
            alert.show(); 
        } 
        catch (Exception e) { 
               e.printStackTrace();
        }
    }

 

 

To test your code: 

  • We recommend that you run the test in both test modes: Developer Test Mode (Success) and Developer Test Mode (Failed).
  • In your Android app code:
    • Set the IAP operating mode to the appropriate test mode.
    • All item IDs must match the IDs of registered in-app items. 
  • Your Android app and the in-app items must be registered in Seller Office.
     
  1. Run your code.
    Note: The following steps apply when your code implements getting offered items in a way that is similar to the example code above. 
  2. Verify that the error message 'ErrorVo is null' is not displayed in AlertDialog that indicates your code failed to run.
  3. When the operating mode is Developer Test Mode (Success):
    1. Verify that the Product details page is displayed.
      InAppItems_OfferedItemList.png
       
    2. Review the Product details page:
      1. Verify that all items with the item IDs specified by your code are listed.
      2. For each listed item, verify that the listed item data matches the item data registered in Seller Office.
         
  4. When the operating mode is Developer Test Mode (Failed):
    1. Verify that the Product details page is not displayed.
    2. Review the errorVo object received by OnGetProductsDetailsListener and verify that it indicates an error status.