niewybuch
niewybuch

Reputation: 31

Android In-app Billing, how confirm that product was downloaded

I trying use Dungeons example in my app. In Android development guide it's written that I should confirm delivery product to user sending CONFIRM_NOTIFICATIONS to market, but I don't see it in example or am I wrong? Should I confirm download and my app should remember if content was successfully delivered?

Where is the best place to invoke downloading, in activity using AsyncTask, in ResponseHandler class or different?

Upvotes: 3

Views: 654

Answers (2)

cgwyllie
cgwyllie

Reputation: 413

This is something that I've been wondering about today too. From what I can see, in the Dungeons example, when BillingService#purchaseStateChanged is called, it automatically acknowledges all notifications after verifying the purchases.

See lines 506-509 in the example BillingService.java:

if (!notifyList.isEmpty()) {
    String[] notifyIds = notifyList.toArray(new String[notifyList.size()]);
    confirmNotifications(startId, notifyIds);
}

The solution would appear to be relocating this logic to a place you can manually call when you have completed delivery of your content.

I'm planning to remove that code and make the BillingService#confirmNotifications public so I can call it from my PurchaseObserver implementation when I've delivered my content.

I'll update with the result, but it seems to be a good starting point.

Upvotes: 1

Dhaval Khant
Dhaval Khant

Reputation: 2467

I hope Following Code helps u.

@Override
    public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
            int quantity, long purchaseTime, String developerPayload) {
        if (Consts.DEBUG) {
            Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
        }

        if (developerPayload == null) {
            logProductActivity(itemId, purchaseState.toString());
        } else {
            logProductActivity(itemId, purchaseState + "\n\t" + developerPayload);
        }

        if (purchaseState == PurchaseState.PURCHASED) {
            mOwnedItems.add(itemId);

            Log.v("log_tag", "Item Purchased");

        }
        mCatalogAdapter.setOwnedItems(mOwnedItems);
        mOwnedItemsCursor.requery();
    }

In Log if you get "Item Purchased" it indicates that you have successfully download the Item.

Upvotes: 0

Related Questions