Skip to main content
Samsung Developer Program

Retrieving the Offered Items List

The following procedure describes how to retrieve the list of a specified subset of the commercial items offered for sale by your service app (offered items list). Typically, apps retrieve the list in order to obtain current item details, such as item IDs. For all item details, see OnGetInboxListener().

As is appropriate, apps can use the retrieved item information, display it to the user (shown in the example code), and provide methods for users to initiate IAP purchase and payment processing of user-selected items.

It is recommended to display the offered items list similar to the purchased items list in the ListView format in the purchased items list format using the ListView and AdapterView, as shown in example code. Additionally, the IAP SDK ./Sample/IAP3Sample displays items in a list format using the ListView and AdapterView.

Getting and Displaying a List of Items Offered by Your Service App

In [Your main activity].xml file:

If not previously instantiated, the IAP Helper is instantiated (via getInstance), which explicitly specifies (this) to indicate the context and the IAP operating mode.

An offered items list is requested (via getItemList): the first 15 consumable items offered by the service app, specifies the IAP operating mode, and explicitly specifies (this) the onGetItemListener().

Note: Use getItemList(int, int, String, int, OnGetItemListener) instead of the deprecatedgetItemList(String, int, int, String, int, OnGetItemListener).

The callback onGetItem() displays the results of the request in an AlertDialog: the ItemVO settings for each returned item (successful result), and ErrorVo settings (failed result). 

  1. Define a UI layout button to get an offered items list.
       <!-- Get Item List Button -->
       <Button
            android:id="@+id/btn_get_item_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/load_item_list"
            android:onClick="doGetItemList"/>
    

    doGetItemList() is called to get an offered items list.

  2. Define the method called by the button to instantiate IAP Helper (if not previously instantiated) and to call getItemList().
        public void doGetItemList( View _view )
        {
            if( mIapHelper == null )
            {
                mIapHelper = SamsungIapHelper.getInstance( this, MODE );
            }
            mIapHelper.getItemList( 1, 15, "00", MODE, this );
        }
  3. Implement the OnGetItemListener to be notified when the requested offered items list is available.
       public class MainActivity extends Activity
                               implements OnPaymentListener, OnGetItemListener
       {
    
  4. Implement a callback on the OnGetItemListener interface to display the results of the offered items list request after the final results are received. 
      @Override
       public void onGetItem( ErrorVo _errorVo, ArrayList<ItemVo> _itemList )
       {
            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() ==
                                           SamsungIapHelper.IAP_ERROR_NONE )
                {
                    alert.setTitle( R.string.item_list );
                       
                    String message = "";
                   
                    for( ItemVo vo : _itemList )
                    {
                        message += vo.dump() + "\n" +
                                   "--------------------------------------"
                                   + "\n";
                    }
                       
                    alert.setMessage( message );
                }
                else
                {
                    alert.setTitle( R.string.item_list );
                    alert.setMessage( _errorVo.getErrorString() );
                }
            }
            else
            {
                alert.setTitle( R.string.item_list );
                alert.setMessage( "ErrorVo is null" );
            }              
                 try
           {
                alert.show();
            }
            catch( Exception e )
            {
                e.printStackTrace();
            }
        }

To test the get and display offered items list code:

  1. On a test device in Android Studio 1.1.0, run the purchasing code.
  2. Verify that an item list similar to below is displayed in the AlertDialog. The item list can be displayed in list format using the ListView and AdapterView similar to the _inboxList.
  3. If the list request fails, an error message is displayed in the AlertDialog.
  • Was this article helpful?