我正在使用应用内购买为我的测验应用购买coins.And我已经分别添加了2个硬币类别100硬币和500个硬币。我也增加了2个SKU.My两个硬币购买尽管我购买了100个硬币并消耗了100个硬币,但是当我再次购买500个硬币时,100个硬币被添加了,而不是500个。我真的需要一个帮助,因为我坚持了几个星期。这里是在消费应用申购代码关于应用内购买:Android
private void update() {
ArrayList<String> moreSkus = new ArrayList<String>();
moreSkus.add(SKU);
moreSkus.add(SKU_500);
buyHelper.queryInventoryAsync(true, moreSkus, new QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
if(result.isSuccess()) {
// SkuDetails details = inv.getSkuDetails(SKU);
//String price = details.getPrice();
//TextView tvPrice = (TextView)GameActivity.this.findViewById(R.id.textview_price);
// tvPrice.setText(price);
purchase = inv.getPurchase(SKU);
// purchase = inv.getPurchase(SKU_500);
purchase=inv.getPurchase(SKU_500);
if(purchase!=null) {
// buy100coins.setEnabled(false);
//coins_one_hundred.setVisibility(View.GONE);
// buy100coins.setVisibility(View.GONE);
buy100coins.setEnabled(false);
buy500coins.setEnabled(false);
//boughtcoins.setEnabled(true);
//boughtcoins.setVisibility(View.VISIBLE);
boughtcoins.setEnabled(true);
} else {
// buy100coins.setEnabled(true);
//coins_one_hundred.setVisibility(View.VISIBLE);
// buy100coins.setVisibility(View.VISIBLE);
buy100coins.setEnabled(true);
buy500coins.setEnabled(true);
//boughtcoins.setEnabled(false);
//boughtcoins.setVisibility(View.INVISIBLE);
boughtcoins.setEnabled(false);
}
Toast.makeText(GameActivity.this, "Successful got inventory!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(GameActivity.this, "Error getting inventory!", Toast.LENGTH_SHORT).show();
}
}
});
}
和按钮,消耗
boughtcoins = (Button) buycoinsdialog.findViewById(R.id.bought_coins);
//boughtcoins.setVisibility(View.GONE);
// if button is clicked, close the custom dialog
boughtcoins.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Helper.playSound(getApplicationContext(), "click");
buyHelper.consumeAsync(purchase, new OnConsumeFinishedListener() {
@Override
public void onConsumeFinished(Purchase purchase, IabResult result) {
if(result.isSuccess()) {
Toast.makeText(GameActivity.this, "Coins consumed!", Toast.LENGTH_SHORT).show();
Helper.playSound(getApplicationContext(), "cash");
money += 100;
money_text.setText("$" + money);
try {
// Small HACK: Give the system some time to realize the consume... without the sleep here,
// you have to press "Update" to see that the item can be bought again...
Thread.sleep(600);
update();
} catch(Exception e) {
// ignored
}
} else {
Toast.makeText(GameActivity.this, "Error consuming: "+result.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
buycoinsdialog.dismiss();
}
});
您要添加的钱+ = 100;只适用于两种购买。检查这个。 – Rama
@Rama我试图将其改为500,即如果(purchase.getsku()。等于(SKU){}但它不起作用 –
@Rama我不确定上面的代码即在update()方法内。添加第二个SKU到它? –