Billing service unavailable on device. (response: 3:Billing Unavailable)
Asked Answered
P

3

10

I've been struggling with this problem for days now. I know there are a lot of questions with the same problem on SO but i couldn't get it to work.

What I have done

  • Uploaded APK in beta phase
  • Created Merchant account
  • Added test user

Code

AndroidManifest.xml

<uses-permission android:name="com.android.vending.BILLING" />

MainActivity.java

public class MainActivity extends AppCompatActivity {
    private IabHelper mHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // ...
        
        setupInAppBillings();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
    
    // [....]

    private void setupInAppBillings() {
        String base64EncodedPublicKey = "MY PUBLIC KEY";

        mHelper = new IabHelper(this, base64EncodedPublicKey);
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    Toast.makeText(getContext(), "In-app Billing setup failed: " + result, Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getContext(), "In-app Billing is set up OK", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}

Tested on

  • Huawei P8 (Google Play Version 6.2.14)
  • In Switzerland, so a supported country for In-App Billing

What I've tried

The only thing I haven't done from this list is the setup of the License Verification Library (LVL). But I couldn't find any information that this step is required for an In-App Purchase. If not needed I want to do it without this library because I don't really need it as stated on the Google Site.

The Google Play Licensing service is primarily intended for paid applications that wish to verify that the current user did in fact pay for the application on Google Play.

Is there something I miss?

Patio answered 1/4, 2016 at 8:28 Comment(4)
Try this: #15618897Domesticity
@Domesticity Thanks for your comment. Unfortunately I already deleted the cache and data of the Google Play app as stated in the question. That didn't work.Patio
ok did you upload and also publish your apk?Domesticity
Yes, the APK is uploaded and published in a closed beta testPatio
P
3

Finally I got it to work! The problem was the following: Even though I put the IInAppBillingService.aidl in the com.android.vending.billing package, the generated class was in the wrong package as you can see in the code below.

/*
* This file is auto-generated.  DO NOT MODIFY.
* Original file:     C:\\path\\src\\main\\aidl\\com\\android\\vending\\billing\\IInAppBillingService.aidl
*/
package billing;

public interface IInAppBillingService extends android.os.IInterface { //... }

To solve this, I deleted and recreated the com.android.vending.billing package with the IInAppBillingService.aidl. So if you have the same problem, check twice where the IInAppBillingService.java was generated.

Patio answered 4/4, 2016 at 18:5 Comment(0)
E
5

if you target android 31 you should add this to your manifest :

<queries>
    <intent>
        <action android:name="android.intent.action.MAIN" />
    </intent>
</queries>
Eldwin answered 27/4, 2022 at 6:22 Comment(1)
any explanation on what does that mean? my understanding is: you're specifying that your app intends to interact with "android.intent.action.MAIN" so what is that? The android.intent.action.MAIN is defined to let the Android Operating System (OS) knows what Activity class to run when the application is started.Likeminded
P
3

Finally I got it to work! The problem was the following: Even though I put the IInAppBillingService.aidl in the com.android.vending.billing package, the generated class was in the wrong package as you can see in the code below.

/*
* This file is auto-generated.  DO NOT MODIFY.
* Original file:     C:\\path\\src\\main\\aidl\\com\\android\\vending\\billing\\IInAppBillingService.aidl
*/
package billing;

public interface IInAppBillingService extends android.os.IInterface { //... }

To solve this, I deleted and recreated the com.android.vending.billing package with the IInAppBillingService.aidl. So if you have the same problem, check twice where the IInAppBillingService.java was generated.

Patio answered 4/4, 2016 at 18:5 Comment(0)
T
1

I recently faced this problem. As Bona Fide wrote, the package declaration in IInAppBillingService.aidl must be set to "com.android.vending.billing" and the aidl file should be found inside the corresponding directory using the explorer. Furthermore (and that was the problem in my case), in the IabHelper.java, the string parameter to serviceIntent must be the same as the package name that contains the IInAppBillingService.aidl file.

Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");// correct package name: com.android.vending.billing

    serviceIntent.setPackage("com.android.vending");
    List<ResolveInfo> intentServices = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
    if (intentServices != null && !intentServices.isEmpty()) {
        // service available to handle that Intent
        mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    }
    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."));
        }
    }
}
Trinomial answered 24/8, 2017 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.