Streetboy
Streetboy

Reputation: 4401

'Could not bind to service' on Android LicenseChecker

I am trying to implement Android License. Did everything by instructions. But when need to close app due to un license use. i get exeption:

06-12 09:11:31.384: E/LicenseChecker(383): Could not bind to service.
06-12 09:11:36.884: E/ActivityThread(383): Activity com.myapp.main.mactivity has leaked ServiceConnection com.google.android.vending.licensing.LicenseChecker@406a4428 that was originally bound here
06-12 09:11:36.884: E/ActivityThread(383): android.app.ServiceConnectionLeaked: Activity com.myapp.main.mactivity has leaked ServiceConnection com.google.android.vending.licensing.LicenseChecker@406a4428 that was originally bound here
06-12 09:11:36.884: E/ActivityThread(383):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:932)
06-12 09:11:36.884: E/ActivityThread(383):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:827)
06-12 09:11:36.884: E/ActivityThread(383):  at android.app.ContextImpl.bindService(ContextImpl.java:1082)
06-12 09:11:36.884: E/ActivityThread(383):  at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
06-12 09:11:36.884: E/ActivityThread(383):  at com.google.android.vending.licensing.LicenseChecker.checkAccess(LicenseChecker.java:150)

What could cause this ?

onCreate method i create:

mHandler = new Handler();

// Try to use more data here. ANDROID_ID is a single point of attack.
String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

// Library calls this when it's done.
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
// Construct the LicenseChecker with a policy.
mChecker = new LicenseChecker(
    this, new ServerManagedPolicy(this,
        new AESObfuscator(SALT, getPackageName(), deviceId)),
    BASE64_PUBLIC_KEY);
doCheck();

and onDestroy:

@Override
protected void onDestroy() {
    super.onDestroy();
    mChecker.onDestroy();
}

So what this exception means really?

Upvotes: 2

Views: 3513

Answers (2)

Splaktar
Splaktar

Reputation: 5904

I just ran into this as well. I was testing with an AVD Galaxy Nexus with 4.0.4.

I tried other thread's suggestions to use getApplicationContext() instead of using the current activity's context. But that did not help.

Switching to a real device did indeed fix the issue as mentioned in the comments.

The other option that may work is the following:

  1. Use a Google API based Emulator (Configured in AVD Manager).
  2. Add a Google account to the emulator in Settings.
  3. Verify that the above account is in your list of testers for Android Licensing in the Play Store Dev Console.

Upvotes: 2

iwasrobbed
iwasrobbed

Reputation: 46713

If you're using the emulator instead of a device:

  1. Make sure that your emulator is running on the Google APIs, not the Android APIs. You can set this up in the virtual device manager
  2. Once your emulator is running on the correct APIs, open up the emulator and then goto Settings -> Add Account and login with your Gmail testing account (the same one that you should have set up in Google Play to have the proper license response)
  3. Once you're signed in, run your app and it should run properly on the emulator

The basic problem is that you aren't logged in to a valid testing account when you try to run the app on the emulator.

Upvotes: 1

Related Questions