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

标签 android google-play in-app-billing in-app

我目前正在开发一款游戏并尝试实现 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/

相关文章:

android - Google Play 统计数据 "Active users"显示 2014 年 6 月急剧下降?

一次性购买的 Android 实时开发者通知是一半工作

java.util.hashmap$values 无法在 android putExtra 方法中转换为 java.io.serialized

Android setBackgroundResource 释放内存?

android - 即使应用程序被杀死,WhatsApp也喜欢在android中调用通知

flutter - 使用 Flutters 应用内购买插件检查订阅有效性?

Android - 通过服务器端验证保护应用内购买

android - 蓝牙 LE 设置广告 channel - Android

android - 请求用户对 Android Market 进行评分/评论/评论

Android Google Play 更改应用名称