我正在尝试让 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 方法不起作用?
谢谢!