android 应用内结算,错误响应 -1002
android in-app billing, bad response -1002
我正在学习如何根据这篇文章实施应用内结算 - http://www.techotopia.com/index.php/Integrating_Google_Play_In-app_Billing_into_an_Android_Application_%E2%80%93_A_Tutorial
每次我在 DEBUG 模式下尝试 运行 这个应用程序时,我都会收到错误消息,指出“Google Play Store”已崩溃,我的日志显示
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
此外,我在 RELEASE 模式下成功 运行 google 名为 Trivial Drive 的示例,但是当我用测试 1(例如 android.test.purchased)和 运行 在 DEBUG 模式下的应用程序我得到了同样的错误。
完整 activity 代码
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;
}
从您的日志来看,我认为您发送了错误的参数。
在我的申请中
对于托管产品,我使用这些参数
mHelper.launchPurchaseFlow(this, SKU, PURCHASE_REQUEST, mPurchaseFinishedListener, payload);
对于订阅产品,我使用这些参数
mHelper.launchPurchaseFlow(this, SKU, IabHelper.ITEM_TYPE_SUBS, oldSkus, PURCHASE_REQUEST, mPurchaseFinishedListener, payload);
试试这些可能对你有帮助..
嘿,这只是因为 google Play 商店更新。
你把每一件事都做得很完美
所以没有必要对这次崩溃采取任何措施。请等待 Google Play 商店应用的错误修复。
有关模式的详细信息,您可以查看此
编辑:2017 年 8 月 11 日
现在在新 google Play 商店版本 8.0.73.R-all [0] [PR] 162689464 google fix 这个 崩溃 问题,我已经在我的设备上成功测试了它,所以现在你不会再遇到这个问题了。 :)
我正在学习如何根据这篇文章实施应用内结算 - http://www.techotopia.com/index.php/Integrating_Google_Play_In-app_Billing_into_an_Android_Application_%E2%80%93_A_Tutorial
每次我在 DEBUG 模式下尝试 运行 这个应用程序时,我都会收到错误消息,指出“Google Play Store”已崩溃,我的日志显示
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
此外,我在 RELEASE 模式下成功 运行 google 名为 Trivial Drive 的示例,但是当我用测试 1(例如 android.test.purchased)和 运行 在 DEBUG 模式下的应用程序我得到了同样的错误。
完整 activity 代码
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;
}
从您的日志来看,我认为您发送了错误的参数。 在我的申请中
对于托管产品,我使用这些参数
mHelper.launchPurchaseFlow(this, SKU, PURCHASE_REQUEST, mPurchaseFinishedListener, payload);
对于订阅产品,我使用这些参数
mHelper.launchPurchaseFlow(this, SKU, IabHelper.ITEM_TYPE_SUBS, oldSkus, PURCHASE_REQUEST, mPurchaseFinishedListener, payload);
试试这些可能对你有帮助..
嘿,这只是因为 google Play 商店更新。
你把每一件事都做得很完美
所以没有必要对这次崩溃采取任何措施。请等待 Google Play 商店应用的错误修复。
有关模式的详细信息,您可以查看此
编辑:2017 年 8 月 11 日
现在在新 google Play 商店版本 8.0.73.R-all [0] [PR] 162689464 google fix 这个 崩溃 问题,我已经在我的设备上成功测试了它,所以现在你不会再遇到这个问题了。 :)