0

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!

Genadinik
  • 18,153
  • 63
  • 185
  • 284
  • Have you Logged out the itemId's to see their **actual** values? – Blundell Aug 28 '12 at 17:06
  • @Blundell yes, and the value was "3" which is very very strange to me :) – Genadinik Aug 28 '12 at 17:16
  • Did you declare the ID 3 & 4 on Google play (dev. console?) –  Aug 28 '12 at 22:30
  • @RC. yes, they are published items. In fact, the system is billing people but they are not able to get to the article they bought LOL :) ...luckily I put that stuff in an obscure part of the app so few people are facing this issue. – Genadinik Aug 29 '12 at 00:42
  • USB debug on a device, make the purchase, check the adb log. I would bet on a security issue (see `Security` in the SDK sample) –  Aug 29 '12 at 05:21
  • @RC. I never used that technique. I read a little bit about an adb log, and not quite sure - is it the Logcat like they are talking about here: http://stackoverflow.com/questions/2882253/how-do-i-get-the-logfile-from-an-android-device or is it another type of log? – Genadinik Aug 29 '12 at 13:13
  • @RC. I just tried to do this from my C drive in the dis shell of my windows laptop, and I got access denied error: C:\>adb shell logcat > log.txt Access is denied. – Genadinik Aug 29 '12 at 13:16
  • @Genadinik try `adb logcat` or use aLogCat app from market (it's free) –  Aug 29 '12 at 15:20
  • @RC. what kind of a security issue could it be? Would it create an exception? How can I try to catch it in the code? Thanks for all your help!!! – Genadinik Aug 29 '12 at 23:27
  • I think you took some part of the SDK sample and forgot to edit them, there's a `Security` class where you need to put you own public key. What does your logcat says? –  Aug 30 '12 at 06:04

0 Answers0