Reputation: 2716
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
Toast
comes from. I couldn't find out it my code.Reserved product ID
I used? Will it change once I use my own product Ids? @Override
public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
long purchaseTime, String developerPayload) {
if (purchaseState == PurchaseState.PURCHASED) {
// Is it here?
}
}
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
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