5

I am trying to implement in-app billing in my application based on Sample Application. But bindService always returns false.

Here is what I have. AndroidManifest.xml:

<service android:name="tv.app.billing.BillingService" />

Preferences.java (need to start purchase from Preferences screen):

protected void onCreate(Bundle savedInstanceState) {
    mBillingService = new BillingService();
    mBillingService.setContext(this); // tried to use getApplicationContext also

BillingService.java: public class BillingService extends Service implements ServiceConnection {

/**
 * Binds to the MarketBillingService and returns true if the bind
 * succeeded.
 * @return true if the bind succeeded; false otherwise
 */
private boolean bindToMarketBillingService() {
    try {
        if (Debug.DEBUG) {
            Log.i(TAG, "binding to Market billing service");
        }
        boolean bindResult = bindService(
                new Intent(Consts.MARKET_BILLING_SERVICE_ACTION),
                this,  // ServiceConnection.
                Context.BIND_AUTO_CREATE);

        if (bindResult) {
            return true;
        } else {
            Log.e(TAG, "Could not bind to service.");
        }
    } catch (SecurityException e) {
        Log.e(TAG, "Security exception: " + e);
    }
    return false;
}

And in LogCat I see:

WARN/ActivityManager(48): Unable to start service Intent { act=com.android.vending.billing.MarketBillingService.BIND }: not found

What do I need to correct here?

LA_
  • 19,823
  • 58
  • 172
  • 308
  • 1
    Strange, but it doesn't work on emulator only and works on actual device. Probably, I should wait for the service to start? – LA_ Apr 09 '11 at 17:04

4 Answers4

8

Ok, it can not be tested on the emulator (since it doesn't have Android Market?). Testing In-app Billing section of official site says

You cannot use the Android emulator to test in-app billing

LA_
  • 19,823
  • 58
  • 172
  • 308
4

You are right, the billing is not supported by the emulator, but you can use this test framework : android-test-billing to test the In-App billing on the emulator. This framework was used in the project Horer - horaire de RER to simplify the integration.

battlmonstr
  • 5,841
  • 1
  • 23
  • 33
1

Have you declared a reciever in your manifest ? (source)

    <receiver android:name="BillingReceiver">
      <intent-filter>
        <action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
        <action android:name="com.android.vending.billing.RESPONSE_CODE" />
        <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
      </intent-filter>
    </receiver>

Quote:

In the sample application, BillingReceiver is the BroadcastReceiver that handles broadcast intents from the Android Market application and BillingService is the Service that sends requests to the Android Market application

Mark Mooibroek
  • 7,636
  • 3
  • 32
  • 53
1

Please put bindToMarketBillingService() in onServiceConnected.

Because when it finishes binding, it will call back and return IBinder to your connection.

I am 100% sure that this will work!

chown
  • 51,908
  • 16
  • 134
  • 170
George Nguyen
  • 2,169
  • 1
  • 16
  • 7