4

I am using following code:

public class MyBillingService extends Service implements ServiceConnection
{
    String TAG = "MyBillingService";

    @Override
    public void onCreate() 
    {
        super.onCreate();
        Log.i(TAG, "onCreate");

        try {
            boolean bindResult = getBaseContext().bindService(
                new Intent(IMarketBillingService.class.getName()), this, Context.BIND_AUTO_CREATE);
            if (bindResult) {
                Log.i(TAG, "Service bind successful.");
            } else {
                Log.e(TAG, "Could not bind to the MarketBillingService.");
            }
        } catch (SecurityException e) {
            Log.e(TAG, "Security exception: " + e);
        }
    }
}

I have also added the IMarketBillingService.aidl but still it show like:

Could not bind to the MarketBillingService

Can you point out my mistake?

dave.c
  • 10,910
  • 5
  • 39
  • 62
Vijay
  • 2,005
  • 1
  • 14
  • 15

2 Answers2

0

I was testing on an old Android device which had a clean system install. This didn't have a copy of the Google Market app on it (hat tip @sstn).

So I logged in with a Google account, then launched the Market. That prompted me to agree to terms and the Google Play app appeared in the list of applications.

Then I removed and reinstalled my app and it bound to the service correctly!

Jonathon Horsman
  • 2,303
  • 1
  • 20
  • 18
0

I don't know if this is the cause for your problem, but you are using bindService() on getBaseContext(). Is there a reason that you don't call bindService() on the service instance? That's what the example service does.

The base context seems to be mostly unneeded and the general advice seems to not use it. See the other question: What's the difference between the various methods to get a Context?

Besides that, you need to have the newest (or at least a recent) version of the Android Market App on your device, although I assume that it updates itself.

There is a way to test if the market app supports In-App Billing, somewhere described in the In-App-Billing reference. I assume that it is worth to do that check.

Community
  • 1
  • 1
sstn
  • 3,050
  • 19
  • 32