我正在努力让Android结算工作。感觉就像我做对了,当我在我的设备上测试时,我得到了正确的行为,但是当我在实时应用上发布结算时,它无法正常工作。
以下是我的工作:
@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
}
}
我称之为:
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 )
{ }
}
});
有人知道为什么当itemId为“3”时onStateChange方法不起作用而不是一个有效的测试值吗?
谢谢!