我正在尝试使用 IabHelper 实现 inApp 计费服务。我设法毫无问题地完成了整个购买过程。
//-----------------------------------------------
public void billingServiceLaunchPurchase(String item) {
//-----------------------------------------------
if (isNetworkAvailableSync(getBaseContext())) {
currBuyItem=item;
billingConsummeType=1;
mHelper.launchPurchaseFlow(BaseActivity.this, item, 10001, mPurchaseFinishedListener, "");
}
else {
onBillingServiceFailed();
}
}
//-----------------------------------------------
mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
//-----------------------------------------------
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (result.isFailure()) {
// Handle error
onBillingServiceFailed();
return;
}
else if (purchase.getSku().equals(currBuyItem)) {
billingServiceConsumeItem();
}
}
};
@Override
//-----------------------------------------------------------------------
protected void onActivityResult(int requestCode, int resultCode, Intent data)
//-----------------------------------------------------------------------
{
if (billingServiceConnected) {
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
else {
// onActivityResult handled by IABUtil.
}
}
else
super.onActivityResult(requestCode, resultCode, data);
}
但是,当用户启动购买时,我无法检测到该事件,然后在 Google 确认屏幕上按下“购买”按钮以中断它。
它既不会触发 onIabPurchaseFinished 失败,也不会触发 onActivityResult,因此我的应用程序处于中间状态。
请帮我解决我的问题。