I am trying to get Android billing to work. It feels like I got it right, and when I test on my device I get the correct behavior, but when I release the billing on the live app, it doesn't work right.
Here is what I do:
@Override
public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
int quantity, long purchaseTime, String developerPayload)
{
if (purchaseState == PurchaseState.PURCHASED)
{
// Product ids are "3" and "4"
if ( itemId != null && itemId.trim().equals("android.test.purchased") )
{
// DURING TESTING THIS WORKS AND GETS INTO THIS IF CASE
Intent myIntent = new Intent(ExtraHelpActivity.this, PsychologyActivity.class);
ExtraHelpActivity.this.startActivity(myIntent);
}
else
if ( itemId != null && itemId.trim().equals("3") )
{
// WHEN THE USER BUYS PRODUCT WITH ID "3" FOR SOME REASON CODE DOES NOT GET HERE.
Intent myIntent = new Intent(ExtraHelpActivity.this, PsychologyActivity.class);
ExtraHelpActivity.this.startActivity(myIntent);
}
else
if ( itemId != null && itemId.trim().equals("4") )
{
Intent myIntent = new Intent(ExtraHelpActivity.this, NumberOfBusinessesActivity.class);
ExtraHelpActivity.this.startActivity(myIntent);
}
}
else
if (purchaseState == PurchaseState.CANCELED)
{
// purchase canceled
}
else
if (purchaseState == PurchaseState.REFUNDED)
{
// user ask for a refund
}
}
and I call this like this:
Button psychology = (Button)findViewById(R.id.psychology);
psychology.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
if(mBillingService.checkBillingSupported(Consts.ITEM_TYPE_INAPP))
{
//OK
}
else
{
// Send them to the screen of the article.
Intent myIntent = new Intent(ExtraHelpActivity.this, PsychologyActivity.class);
ExtraHelpActivity.this.startActivity(myIntent);
}
try
{
if (mBillingService.requestPurchase(issueProductIdPsych,
Consts.ITEM_TYPE_INAPP , null))
{
}
}
catch ( Exception e )
{ }
}
});
Would anyone have an idea why the onStateChange method does not work when the itemId is "3" and not a testing value which does work?
Thanks!