Not being able to establish connection for In app

2019-01-27 07:40发布

问题:

I am trying to integrate In app billing v3 in my app. I call the following function to initialize.

public static void SetupInappBilling()
{
    mHelper = new IabHelper(context, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() 
    {
        public void onIabSetupFinished(IabResult result) 
        {
            if (result.isSuccess())
            {
                Log.e("tag", "connected");
                ConnectionEstablished = true;

            } 
            else
            {
                    Log.e("tag", "not connected");

                    ConnectionEstablished = false;
                }
            }
        });
    }

but i dont get call back in OnIabSetupFinishedListener Can anyone tell me how to fix this issue

回答1:

As discussed, the example IabHelper implementation ignores the return value of the bindService() call.

bindService() returns false if it cannot bind to the Service. In this case, no callbacks will ever get called. In this respect, the return value of bindService() is essential for the program logic and should never be ignored; the example application is not exactly perfect here.

If I recall this correctly, conditions where binding to the IAB V3 will not work are:

  • Only IAB V2 is available (it uses a different class name)
  • Google Play is not fully set up