使用IabHelper时无法绑定InAppBillingService

问题描述 投票:1回答:3

我目前正在开发游戏,并尝试实施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

有什么想法有什么不对吗?提前致谢。

android google-play in-app-billing in-app
3个回答
1
投票

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


0
投票

从Project“Trivial”复制util文件夹中的所有类,或者可以将整个Util包复制到项目中。然后尝试一下。


0
投票

我有这个问题,并发现了

  1. 调试的应用程序版本必须与开发人员控制台中发布的版本相同。
  2. 播放服务需要可用,有些手机可能会在屏幕锁定后实际终止服务,开始播放存储,然后重做绑定工作。
  3. 使用开箱即用的IabHelper可能会触发服务断开未处理,重新初始化失败等问题,我不得不稍微修改一下。
© www.soinside.com 2019 - 2024. All rights reserved.