Skip to main content
Samsung Developer Program

Retrieving and Caching a Purchased Items List

Available starting with IAP 3.0 Helper, you can optionally retrieve a purchased items list and have it cached on the client. Subsequent loading of a client‑cached purchased items list is faster after the initial loading, because client caching is supported. Additionally, this method retrieves a purchased items list for only the specified product item IDs.

To create an example using this method, add the files that were used in a previous section to the InboxListAdapter.java, inbox_list_layout.xml, and inbox_row.xml.

To get and cache a list of specified items purchased by the user:

    <!-- Cached InboxList Button -->
    <Button
        android:id="@+id/btn_get_cached_inbox_list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/load_cached_items_inbox_list"
        android:onClick="doGetCachedInBoxList" />
private static final String ITEM_IDS = " Nuclear, Claymore, " +
                                       " Blockbuster";
    public void doGetCachedInBoxList( View _view )
    {
        Intent intent = new Intent( MainActivity.this,
                                    CachedInboxListActivity.class );
       
        intent.putExtra( "IapMode", MODE );
        intent.putExtra( "ItemIds", ITEM_IDS );       

        startActivity( intent );
    }
public class CachedInboxListActivity extends Activity
                                      implements OnGetInboxListener
{
    private int                mIapMode          = 1;
    private String             mItemIds          = "";   

    private SamsungIapHelper   mIapHelper        = null;

       private ListView           mInboxListView    = null;
    private TextView           mNoDataTextView   = null;
    private ArrayList<InboxVo> mInboxList        = new
                                                   ArrayList<InboxVo>();
    private InboxListAdapter   mInboxListAdapter = null;

    @Override
    protected void onCreate( Bundle savedInstanceState )
    {
        super.onCreate( savedInstanceState );       
        setContentView( R.layout.inbox_list_layout );       

        initView();       

        Intent intent = getIntent();

               if( intent != null && intent.getExtras() != null
                && intent.getExtras().containsKey( "IapMode" )
                && intent.getExtras().containsKey( "ItemIds" ) )
        {
            Bundle extras = intent.getExtras();

            mIapMode = extras.getInt( "IapMode" );
            mItemIds = extras.getString( "ItemIds" );
        }
        else
        {
            Toast.makeText( this,
                            R.string.invalid_parameter,
                            Toast.LENGTH_LONG ).show();
            finish();
        }

        mIapHelper = SamsungIapHelper.getInstance( this, mIapMode );
        mIapHelper.getItemInboxList( mItemIds, this );
    }

    public void initView()
    {
        mInboxListView = (ListView)findViewById( R.id.itemInboxList );
        mNoDataTextView = (TextView)findViewById( R.id.noDataText );
        mNoDataTextView.setVisibility( View.GONE );       

        mInboxListView.setEmptyView( mNoDataTextView );

               mInboxListAdapter = new InboxListAdapter( this,
                                                  R.layout.inbox_row,
                                                  mInboxList );       

        mInboxListView.setAdapter( mInboxListAdapter );
    }

    @Override
    public void onGetItemInbox
    (  
        ErrorVo             _errorVo,
        ArrayList<InboxVo>  _inboxList
    )
    {
        if( _errorVo != null
                && _errorVo.getErrorCode() ==
                                        SamsungIapHelper.IAP_ERROR_NONE )
        {
            if( _inboxList != null && _inboxList.size() > 0 )
            {
                mInboxList.addAll( _inboxList );
                mInboxListAdapter.notifyDataSetChanged();
            }
        }
    }
} 

CautiongetItemInboxList returns a list of all purchased items, regardless of development mode.

   <activity
​            android:name=".CachedInboxListActivity"
            android:label="@string/cached_items_inbox_list" >
   </activity>
  1. Add a button to run CachedInboxListActivity beneath the Purchase One Item button in the activity_main.xml layout, and set it to call the doGetCachedInboxList method when clicked.
  2. Specify new items in MainActivity.java.
  3. Set the required information in the intent and run CachedInboxListActivity by implementing the doGetCachedInboxList method, as shown above in MainActivity.java.
  4. Add the following code to create a CachedInboxListActivity class. 
  5. Add CachedInboxListActivity to AndroidManifest.xml.

To test the cached purchased items list code:

  1. On a test device in Android Studio 1.1.0, run the purchasing code.
  2. Verify that a purchased items list similar to the one below is displayed.
        
  • Was this article helpful?