Billing in Android app, bad answer -1002
I am 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
Every time I try to run this app in DEBUG mode I got an error that says "Google Play Store" crashed and my logs say
E / InAppBilling: Billing error in application: null data as a result of IAB action.
Error: error while purchasing: labResult: null data in IAB result (response: -1002: wrong response received)
Caused by: java.lang.NullPointerException: Attempting to call 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
Also I successfully run a Google sample called Trivial Drive in RELEASE mode, but when I replace the real SKU with a test one (for example android.test.purchased) and run the 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;
}
source to share
Hey, this is only happening because of the new Google play store update.
you did everything perfectly.
Thus, there is no need to do anything about this crash. Wait for the bug fixes in the Google Play Store app.
for mode details you can check this question
EDIT: Aug 11, 2017
Now the new google play store version 8.0.73.R-all [0] [PR] 162689464 google fix this crash issue and i tested it successfully on my devices. now you don't face this problem anymore. :)
source to share
From your log, I think you are sending the wrong parameters. In my application
For a managed product, I use these options
mHelper.launchPurchaseFlow(this, SKU, PURCHASE_REQUEST, mPurchaseFinishedListener, payload);
For a subscription product, I use these parameters
mHelper.launchPurchaseFlow(this, SKU, IabHelper.ITEM_TYPE_SUBS, oldSkus, PURCHASE_REQUEST, mPurchaseFinishedListener, payload);
try it may help you ..
source to share