我在android.Below中进行Inapp计费版本3应用程序是我的代码。在这里Inapp Billing已经启动,购得很好并且它出现了" onProductPurchased"方法。但是如何获得响应代码?谢谢。
代码:
private BillingProcessor bp;
bp = new BillingProcessor(this, LICENSE_KEY,
new BillingProcessor.IBillingHandler() {
@Override
public void onProductPurchased(String productId,
TransactionDetails details) {
//How to get response code from here?
showToast("onProductPurchased: " + productId);
updateTextViews();
}
@Override
public void onBillingError(int errorCode, Throwable error) {
showToast("onBillingError: "
+ Integer.toString(errorCode));
}
@Override
public void onBillingInitialized() {
showToast("onBillingInitialized");
readyToPurchase = true;
updateTextViews();
}
@Override
public void onPurchaseHistoryRestored() {
showToast("onPurchaseHistoryRestored");
for (String sku : bp.listOwnedProducts())
Log.d(LOG_TAG, "Owned Managed Product: " + sku);
for (String sku : bp.listOwnedSubscriptions())
Log.d(LOG_TAG, "Owned Subscription: " + sku);
updateTextViews();
}
});
}
@Override
protected void onResume() {
super.onResume();
updateTextViews();
}
@Override
public void onDestroy() {
if (bp != null)
bp.release();
super.onDestroy();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!bp.handleActivityResult(requestCode, resultCode, data))
super.onActivityResult(requestCode, resultCode, data);
showToast("Result: " + data);
}
private void updateTextViews() {
TextView text = (TextView) findViewById(R.id.productIdTextView);
text.setText(String.format("%s is%s purchased", PRODUCT_ID,
bp.isPurchased(PRODUCT_ID) ? "" : " not"));
text = (TextView) findViewById(R.id.subscriptionIdTextView);
text.setText(String.format("%s is%s subscribed", SUBSCRIPTION_ID,
bp.isSubscribed(SUBSCRIPTION_ID) ? "" : " not"));
}
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
public void onClick(View v) {
if (!readyToPurchase) {
showToast("Billing not initialized.");
return;
}
switch (v.getId()) {
case R.id.purchaseButton:
bp.purchase(this, PRODUCT_ID);
break;
case R.id.consumeButton:
Boolean consumed = bp.consumePurchase(PRODUCT_ID);
updateTextViews();
if (consumed)
showToast("Successfully consumed");
break;
case R.id.productDetailsButton:
SkuDetails sku = bp.getPurchaseListingDetails(PRODUCT_ID);
showToast(sku != null ? sku.toString()
: "Failed to load SKU details");
break;
case R.id.subscribeButton:
bp.subscribe(this, SUBSCRIPTION_ID);
break;
case R.id.updateSubscriptionsButton:
if (bp.loadOwnedPurchasesFromGoogle()) {
showToast("Subscriptions updated.");
updateTextViews();
}
break;
case R.id.subsDetailsButton:
SkuDetails subs = bp.getSubscriptionListingDetails(SUBSCRIPTION_ID);
showToast(subs != null ? subs.toString()
: "Failed to load subscription details");
break;
case R.id.launchMoreButton:
startActivity(new Intent(this, MainActivity.class).putExtra(
ACTIVITY_NUMBER, getIntent()
.getIntExtra(ACTIVITY_NUMBER, 1) + 1));
break;
default:
break;
}
}