Reputation: 2853
I want to do in app billing from my app.
IabHelper.OnIabPurchaseFinishedListener purchaseThisAppListener = new IabHelper.OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result, Purchase purchaseDetails) {
if(result.isFailure()) {
if(result.getResponse() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
String toastText = "Item is already purchased.\nRestoring purchase.";
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());;
prefs.edit().putBoolean("isAppPurchased", true).commit();
myActivity.refresh_status = myActivity.REFRESH_ACTIVITY;
Builder alert = new AlertDialog.Builder(thisActivityContext);
alert.setTitle("Item already owned");
alert.setMessage("You already own this item. Restoring purchase.");
alert.setPositiveButton("OK",null);
alert.show();
for(int i = 3; i < myUtility.isCategoryAvailable.length; i++) {
myUtility.isCategoryAvailable[i] = true;
}
myUtility.isAllCategoriesAvailable = true;
isAppPurchased = true;
}
return;
}
else if (purchaseDetails.getSku().equals(ITEM_SKU)) {
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if(prefs != null) {
prefs.edit().putBoolean(IS_APP_PURCHASED, true).commit();
for(int i = 3; i < myUtility.isCategoryAvailable.length; i++) {
myUtility.isCategoryAvailable[i] = true;
}
myUtility.isAllCategoriesAvailable = true;
isAppPurchased = true;
}
else {
Log.e(TAG, "Preferences not found");
}
}
else {
Log.e(TAG, "Purchase successful, but different Item SKU found");
}
}
};
I also added onActivityResult as I read that the above function is not called. onIabPurchaseFinished never called.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("IN APP ACTIVITY", "ENTERED");
}
else {
Log.d("IN APP ACTIVITY", "DID NOT ENTER");
}
}
All this is working when I put ITEM_SKU = "android.test.purchased"; But, when I publish this app on GooglePlay, !mHelper.handleActivityResult(requestCode, resultCode, data) always returns false. Please help.
Upvotes: 1
Views: 1358
Reputation: 73
There seems to still be a problem with using the static SKU "android.test.purchased" it seems like you're running into a similar problem as outlined in this question: Android in app purchase: Signature verification failed
I had this problem as well, but once I used my own SKU everything worked fine. I think the best way to move forward would be to setup an In-App Product in the developer console as outlined here: http://developer.android.com/intl/es/training/in-app-billing/list-iab-products.html and then test using that and testing accounts (which you can also setup in the console - navigate to settings, account details and scroll down till you see Gmail accounts with testing access) so you don't get charged. It's a bit tedious but it worked for me.
Upvotes: 2