Buying Same Item Over And Over - In App Purchase Android
i want to buy same item over and over but code gives me null pointer exception when try to buy second time. Here is the code; try { Bundle buyIntentBundle = mService.getBuy
Solution 1:
Google prevents users to buy same items. So if you do this, you must tell the google "let me". And this is named "consuming".
Here it's all consuming method
privatevoid consumeBilling() {
try {
Bundle ownedItems = iInAppBillingService.getPurchases(3, getPackageName(), "inapp", null);
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList<String> signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
for (int i = 0; i < purchaseDataList.size(); ++i) {
String purchaseData = purchaseDataList.get(i);
// String signature = signatureList.get(i);// String sku = ownedSkus.get(i);// RDALogger.info("purchaseData " + purchaseData + " signature " + signature + " sku " + sku);
RDALogger.info("purchaseData " + purchaseData);
String purchaseTokenString = new JSONObject(purchaseData).getString("purchaseToken");
int responsee = iInAppBillingService.consumePurchase(3, getPackageName(), purchaseTokenString);
RDALogger.info("Consuming response " + responsee);
}
}
} catch (Exception e) {
e.printStackTrace();
ErrorHandlers.handle(PaymentActivity.this, new HoustonWeGotAProblemException());
}
}
PurschaseToken from purchaseData will go to this code
int responsee = iInAppBillingService.consumePurchase(3, getPackageName(), purchaseTokenString);
after these you told google, this item can be bought again.
Post a Comment for "Buying Same Item Over And Over - In App Purchase Android"