Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android's in-app billing and bindService

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?

like image 947
LA_ Avatar asked Dec 10 '22 09:12

LA_


2 Answers

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

like image 112
LA_ Avatar answered Dec 12 '22 06:12

LA_


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.

like image 25
battlmonstr Avatar answered Dec 12 '22 04:12

battlmonstr