即时通过'android.test.purchased'推出购买流程并按预期工作,但是当选择'购买'并完成购买时,它现在'拥有'该商品并且不会让我再次购买,即使我'很明显得到了 mHelper.consumeAsync(购买,mConsumeFinishedListener);
注意:在购买之前我没有收到任何日志反馈,它告诉我已经拥有的物品。
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d("KFF", "Purchase finished: " + result + ", purchase: " + purchase);
if (result.isFailure()) {
if (result.toString().contains("3")) {
Toast.makeText(Add_User.this, "In app billing unavailable", Toast.LENGTH_SHORT)
.show();
}
else if (result.toString().contains("7")) {
Toast.makeText(Add_User.this, "Item already purchased", Toast.LENGTH_SHORT)
.show();
int n = NetworkUtil.getConnectivityStatus(Add_User.this);
if (n != 0) {
// MAKE RED NAME = TRUE;
}
}
else if (result.toString().contains("6")) {
Toast.makeText(Add_User.this, "Fatal error in in app purchase",
Toast.LENGTH_SHORT).show();
}
else if (result.toString().contains("8")) {
redName = false;
}
return;
}
if (purchase.getSku().equals(RedName.SKU)) {
// bought the premium upgrade!
Log.d("KFF", "Purchase is premium upgrade. Congratulating user.");
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
}
/*
* else if (purchase.getSku().equals(SKU_INFINITE_GAS)) { // bought
* the infinite gas subscription }
*/
}
};
-
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
Log.d("KFF", "Consumption finished. Purchase: " + purchase + ", result: " + result);
if (result.isSuccess()) {
Log.d("KFF", "Consumption successful. Provisioning.");
redName = true;
ChkBox_red.setChecked(true);
ChkBox_red.setEnabled(false);
ChkBox_red.setText("Username will be red!");
}
else {
// complain("Error while consuming: " + result);
Log.d("KFF", "Error while consuming: " + result);
}
Log.d("KFF", "End consumption flow.");
}
};
-
ChkBox_red = ( CheckBox ) findViewById( R.id.check_red );
ChkBox_red.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if ( isChecked )
{
if (mHelper != null) mHelper.flagEndAsync();
mHelper.launchPurchaseFlow(Add_User.this, RedName.SKU, 10002,
mPurchaseFinishedListener);
}
}
});