Reputation: 2520
I am trying to use Android in app purchase. I am using the official documentation and util (Base64 and so on). I am using managed items. Where and how can I handle items, that have been already buyed? (I am setting a boolean to true and save it to sharedpreferences, but if I remove and install the app, the sharedpreferences is lost.)
Now if I click on the "Buy-Button" I am getting "Error 7: Item already owned". The buyed item is something like a pro-version of my app.
Question: Where and how can I handle items, that have been already buyed?
Upvotes: 1
Views: 160
Reputation: 15512
Hi before you show in app purchases screen you should check if you already order non-consumable items before.
Nice article to read:
http://developer.android.com/training/in-app-billing/purchase-iab-products.html
How to call method:
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
return;
}
if (mHelper == null) return;
List<String> st = new ArrayList<String>();
st.add(ITEM_SKU);
mHelper.queryInventoryAsync(true,st,mGotInventoryListener);
}
});
How to query inventory for the items.
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (mHelper == null) return;
if (result.isFailure()) {
return;
}
if(inventory.hasPurchase(ITEM_SKU)) {
Intent intent = null;
intent = new Intent(getActivity(), Ce.class);
startActivity(intent);
}
}
};
Upvotes: 1