Rahmathullah M
Rahmathullah M

Reputation: 2716

Android In App Purchase Problems

I've implemented In App purchase in my account using static response id android.test.purchased. Now when purchase the item a Toast popups saying "Thank you. Your item will appear shortly."

I think so far every thing works perfectly.

My problem is

  • Where does this Toast comes from. I couldn't find out it my code.
  • How can I override this Toast? Is it because of the Reserved product ID I used? Will it change once I use my own product Ids?
  • Which overridden function should be used know whether User has purchased or cancelled the request.

        @Override
        public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
                long purchaseTime, String developerPayload) {       
            if (purchaseState == PurchaseState.PURCHASED) {             
                // Is it here?
            }
        }
    

  • And finally, can I perform User Interface modifications within onPurchaseStateChange?
  • Here's my onPurchaseStateChange methode

        @Override
        public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
                long purchaseTime, String developerPayload) {
            if (Consts.DEBUG) {
                Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
            }            
            if (purchaseState == PurchaseState.PURCHASED) {
                for (CatalogEntry e : CATALOG) {
                    if (e.sku.equals(itemId) &&
                            e.managed.equals(Managed.SUBSCRIPTION)) {
                    }
                }
            }
            Toast.makeText(getApplicationContext(), "purchase failed", Toast.LENGTH_LONG).show();
        }
    

    Any help would be greatly appreciated! :) Thank you!

    Upvotes: 4

    Views: 1023

    Answers (1)

    melodiouscode
    melodiouscode

    Reputation: 2069

    Firstly the toast comes from the market place activity. The link that user1378730 posted in the comments explains about how it gets removed.

    Determining the outcome of the purchase in onPurchaseStateChange as you have done is correct, the purchaseState object has several enumerations that you will be able to check.

    I would not suggest performing interface interactions in the onPurchaseStateChange method, as it may be called several times whilst the purchase is being completed. I jump out of that method to some custom ones on my activity to decide what to do e.g. a onPurchaseCancel and onPurchaseSuccess method that can tell if it's already run it's self. Doing this also allows you to separate the market interactions from the rest of your code flow, makes for easier debugging.

    Upvotes: 2

    Related Questions