gpt4 book ai didi

android - 使用 IabHelper 时绑定(bind) InAppBillingService 失败

转载 作者:行者123 更新时间:2023-11-30 00:31:52 26 4
gpt4 key购买 nike

我目前正在开发一款游戏并尝试实现 Google Play 的应用内结算 V3。我遵循了应用内示例并使用了 IabHelper。但是,在设备中运行该应用程序时,出现了问题。我发现在mHelper.startSetup之后,onServiceDisconnectedonServiceConnected都没有被调用。所以我在 IabHelper 类中打印了 mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); 的结果。结果为 false

这是我的代码:

private IabHelper mHelper;

// MainActivity onCreate
protected void onCreate(Bundle savedInstanceState){
// ...
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;
}
});
}

在IabHelper类的startSetup方法中:

public void startSetup(final OnIabSetupFinishedListener listener) {
// ...
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
// service available to handle that Intent
boolean bRes = mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
// ### I printed the result here it was false
Log.i("IAB", "IAB Service Result = " + bRes);
}
else {
// no service available to handle that Intent
if (listener != null) {
listener.onIabSetupFinished(
new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device."));
}
}
}

我不知道这个问题。我做了:

  • 添加权限:com.android.vending.BILLING
  • 将示例中的 .aidl 文件复制到/src/com/android/vending/billing
  • 我的 android 目标设置为 android-22

有什么问题吗?提前致谢。

最佳答案

最后,我通过将最新版本的游戏上传到开发者控制台并调试最新的 apk 解决了这个问题。问题消失了。希望这对某人有帮助。

关于android - 使用 IabHelper 时绑定(bind) InAppBillingService 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44193357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com