0

我正在处理 Android 计费并尝试正确设置 onPurchaseStateChange 方法,但它似乎不起作用。

    @Override
    public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
            int quantity, long purchaseTime, String developerPayload) 
    {
        if (purchaseState == PurchaseState.PURCHASED) 
        {
            mOwnedItems.add(itemId);

            if ( itemId != null && itemId.trim().equals("3") )
            {
                  Intent myIntent = new Intent(ExtraHelpActivity.this, PsychologyActivity.class);
                  ExtraHelpActivity.this.startActivity(myIntent);
            }
            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
        }
        else
        {   
            if ( itemId != null && itemId.equals("3") )
            {
                  Intent myIntent = new Intent(ExtraHelpActivity.this, PsychologyActivity.class);
                  ExtraHelpActivity.this.startActivity(myIntent);
            }
            if ( itemId != null && itemId.equals("4") )
            {
                  Intent myIntent = new Intent(ExtraHelpActivity.this, NumberOfBusinessesActivity.class);
                  ExtraHelpActivity.this.startActivity(myIntent);   
            }                   
        }

因此,当 purchaseId 为“4”或“3”并且 purchaseState == PurchaseState.PURCHASED ....由于某种原因,它似乎没有进入该 if 语句,并且没有执行转到下一页的意图?

有人知道为什么会这样吗?这似乎很奇怪。它可能是Java的东西吗?

谢谢!

4

1 回答 1

1

PurchaseState 不是原始数据类型,如int, long,float等,因此您应该使用:

purchaseState.equals(PurchaseState.PURCHASED)

而不是==,就像您使用字符串一样:

string1.equals(string2) // Results you expect

不一样

string1 == string2 // Don't do this...
于 2012-08-26T22:28:35.877 回答