4

I'm learning how to implement in-app billing based on this article - http://www.techotopia.com/index.php/Integrating_Google_Play_In-app_Billing_into_an_Android_Application_%E2%80%93_A_Tutorial

Everytime I try to run this app in DEBUG mode I got error that states "Google Play Store" has crashed, and my logs says that

E/InAppBilling: In-app billing error: Null data in IAB activity result.

Error: Error purchasing: labResult: Null data in IAB result (response: -1002: Bad response received)

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getBuyIntent(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)' on a null object reference

HERE I GOT MY ERROR

Also I have successfully run google sample called Trivial Drive in RELEASE mode, but when I replacing real SKU's with test one (for example android.test.purchased) and run app in DEBUG mode I got the same error.

Full activity code

public class InAppBillingActivity extends AppCompatActivity {
private Button clickButton;
private Button buyButton;

private static final String TAG = "InAppBilling";
IabHelper mHelper;

static final String ITEM_SKU = "android.test.purchased";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.billing_activity);
    buyButton = (Button)findViewById(R.id.buyButton);
    clickButton = (Button)findViewById(R.id.clickButton);
    clickButton.setEnabled(false);

    String base64EncodedPublicKey = "HERE IS MY KEY FROM DEVELOPER CONSOLE";
    mHelper = new IabHelper(this, base64EncodedPublicKey);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        @Override
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                Log.d(TAG, "In-app Billing setup failed:" + result);
            } else {
                Log.d(TAG, "In-app Billing is set up OK");
                mHelper.enableDebugLogging(true, TAG);
            }
        }
    });
}

public void buttonClicked (View view) {
    clickButton.setEnabled(false);
    buyButton.setEnabled(true);
}

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        if (result.isFailure()) {// Handle error
            return;
        }
        else if (purchase.getSku().equals(ITEM_SKU)) {
            consumeItem();
            buyButton.setEnabled(false);
        }
    }
};

public void buyClick(View view) {
    mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001, mPurchaseFinishedListener, "mypurchasetoken");
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (!mHelper.handleActivityResult(requestCode,
            resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

public void consumeItem() {
    mHelper.queryInventoryAsync(mReceivedInventoryListener);
}

IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
        if (result.isFailure()) {
            // Handle failure
        } else {
            mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU), mConsumeFinishedListener);
        }
    }
};

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
    public void onConsumeFinished(Purchase purchase, IabResult result) {
        if (result.isSuccess()) {
            clickButton.setEnabled(true);
        } else {
            // handle error
        }
    }
};

@Override
public void onDestroy() {
    super.onDestroy();
    if (mHelper != null) mHelper.dispose();
    mHelper = null;
}
Community
  • 1
  • 1
  • ITEM_SKU is a subscription or managed product which you want to buy??? – Upendra Shah Jul 26 '17 at 13:30
  • To be honest I don't know, I think it's managed product, google static test SKU's doesn't have separation on managed/sub product. Other vars are - android.test.cancelled, android.test.refunded and android.test.item_unavailable. – Dmitry Reznichenko Jul 26 '17 at 13:43
  • But you said on testing product it runs perfectly so on whixh product you get error. – Upendra Shah Jul 26 '17 at 13:45
  • It works only with https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive which I have run in release build variant (I have manually added sku's to developer console etc.), but now I want to have an opportunity to use test sku's like "android.test.purchased" and test my application in debug mode without necessity to generate signed apk and upload it to alpha test on google play store. – Dmitry Reznichenko Jul 26 '17 at 13:49

2 Answers2

4

Hey this is happen just because of new google play store update.
you have done every thing perfect

So there is no need to do anything about this crash. Just wait for bug fixes on Google Play Store App.

for mode details you can check this question

EDIT : Aug 11th 2017
Now in new google play store version 8.0.73.R-all [0] [PR] 162689464 google fix this crash issue and I have successfully tested it on my devices so now you don't face this problem anymore. :)

Harin Kaklotar
  • 305
  • 7
  • 22
0

From your log I think you are sending wrong parameters. In my application

For Managed product I use these parameters

mHelper.launchPurchaseFlow(this, SKU, PURCHASE_REQUEST, mPurchaseFinishedListener, payload);

For subscription product I use these parameters

mHelper.launchPurchaseFlow(this, SKU, IabHelper.ITEM_TYPE_SUBS, oldSkus, PURCHASE_REQUEST, mPurchaseFinishedListener, payload);

try these it may be help you..

Upendra Shah
  • 2,218
  • 17
  • 27
  • Thanks for your attempt, but it doesn't work, refering to https://developer.android.com/google/play/billing/billing_testing.html#billing-testing-static "android.test.purchased" static SKU can't be classified as managed/subscription product, so our parameters are identical. – Dmitry Reznichenko Jul 26 '17 at 16:02
  • 1
    Sadly, no, seems that Harin Kaklotar's answer above is right, and I just have to wait for google to fix this issue. – Dmitry Reznichenko Aug 02 '17 at 10:35