Android Question

Android in app billing - How to know which users have bought a product

I have an android app with a donation system, these donations are integrated products that are automatically consumed to let the users donate more than once.

I need to know if there is some way to find out which users have donated at least once.

I appreciate any help.


In addition to Dima Kozhevin's answer... I used this code in

event inside
method from my

Bundle purchaseHistoryBundle = mService.getPurchaseHistory(6,BuildConfig.APPLICATION_ID, "inapp", null, new Bundle());
ArrayList<String> mListItems = purchaseHistoryBundle.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
if (mListItems != null){
if (mListItems.size()>0){
//User have donated at least once
//User never donated

Answer Source

You should use getPurchaseHistory() method. Signature of the method:

Bundle getPurchaseHistory(int apiVersion,
                          String packageName,
                          String type,
                          String continuationToken,
                          Bundle extraParams);

Your code will look like this:

Bundle purchaseHistoryBundle = service.getPurchaseHistory(6, BuildConfig.APPLICATION_ID, "subs", null, new Bundle());

In addition, guy from Google suggests in that example use queryPurchaseHistoryAsyncmethod:

This library also allows to get purchase history even though it's not demonstrated inside the sample. Please use this method to get all purchases history (up to 1 record per SKU).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download