Android In-app Billing, Non Consumable Items
I'm implementing in-app billing where the user shall be able to buy access to premium content. This is typical non-consumable items. (Let's say the premium content is extra questio
Solution 1:
If you don't want consume, then don't use consumeAsync.
@OverridepublicvoidonQueryInventoryFinished(IabResult result, Inventory inv)
{
if (result.isFailure())
{
Log.e(TAG, "In-app Billing query failed: " + result);
return;
} else
{
booleanhasPurchased_ITEM_SKU_PURCHASE_1= inv.hasPurchase(ITEM_SKU_PURCHASE_1);
SharedPreferencessharedPref= PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editoreditor= sharedPref.edit();
editor.putBoolean(KEY_PREF_PURCHASE_1_AVAILABLE, !hasPurchased_ITEM_SKU_PURCHASE_1);
editor.commit();
// You can update your UI here, ie. Buy buttons.
}
}
You can use the sharedpref to store the purchase info, and also check every onCreate of the activity and update the sharedpref accordingly. The key part on how to check if a SKU is purchased is:
booleanhasPurchased_ITEM_SKU_PURCHASE_1= inv.hasPurchase(ITEM_SKU_PURCHASE_1);
Do your query sync in your IAP setup and update your UI accordingly.
mHelper.startSetup(newIabHelper.OnIabSetupFinishedListener() {
publicvoidonIabSetupFinished(IabResult result)
{
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " +
result);
} else {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
Log.d(TAG, "In-app Billing is set up OK");
}
}
});
Post a Comment for "Android In-app Billing, Non Consumable Items"