我尝试再次购买商品时收到以下错误消息。请不要将其作为副本关闭。我知道堆栈溢出有很多这样的问题,但似乎都没有帮助。请参考我的代码。
public class BtnListener implements View.OnClickListener
{
// On-click event handler for all the buttons
@Override
public void onClick(View view)
{
switch (view.getId())
{
case R.id.TwoSeconds:
mHelper.launchPurchaseFlow(TimeBoosterActivity.this, ITEM_SKU, 10001,
mPurchaseFinishedListener, "2");
break;
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
if (!mHelper.handleActivityResult(requestCode,
resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase)
{
if (result.isFailure()) {
// Handle error
return;
}
else if (purchase.getSku().equals(ITEM_SKU)) {
consumeItem();
//buyButton.setEnabled(false);
}
}
};
public void consumeItem() {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
Toast.makeText(getApplicationContext(), "Failed to consume item",
Toast.LENGTH_SHORT).show();
} else {
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
mConsumeFinishedListener);
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {
if (result.isSuccess()) {
String getSeconds=purchase.getDeveloperPayload();
SharedPreferences saveTwoSeconds=getSharedPreferences(getSeconds, Context.MODE_PRIVATE);
//clickButton.setEnabled(true);
} else {
// handle error
Toast.makeText(getApplicationContext(), "Failed to consume item",
Toast.LENGTH_SHORT).show();
}
}
};
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
答案 0 :(得分:0)
首先,您需要清楚为什么会出现此错误(错误回复:7:项目已经拥有)
有一些常见的情况:
①你只是购买itemA而不是消费它;
②另一个人(与您使用相同的Google帐户)只需购买此商品A
案例1:只需使用itemA,您就可以再次购买。
案例2:您需要重新启动或删除Google Play服务并播放商店缓存。然后使用相同的Google Play帐户使用该项目。
在案例2中,itemA的收据信息未存储在您的设备中。您重新启动或删除Google Play服务并播放商店缓存,以便向Google商店发送应用内结算请求,以获取购买的收据信息。所以你不能再消费和购买它。
答案 1 :(得分:0)
我认为由于您在onActivityResult中的代码而没有调用您的Consume购买。
尝试使用以下代码
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data){
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == <Code you sent during launching purchase flow> || requestCode == <Code you sent during launching consume flow> )
mHelper.handleActivityResult(requestCode,resultCode, data))
}
}