Android billing and bindService application

I am trying to implement billing in an application in my application based on an example application . But bindService always returns false .

Here is what I have. AndroidManifest.xml

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

Preferences.java (you need to start the purchase from the settings 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 fix here?

+4
source share
4 answers

Well, it cannot be tested on an emulator (since it does not have an Android Market?). Testing In-app Billing on the official website says

You cannot use the Android emulator to test billing in the application

+8
source

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

+3
source

Did you declare the receiver 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 a BroadcastReceiver that handles broadcast intentions from Android Market Application and BillingService is a Service that sends requests to the Android Market application

+1
source

Put bindToMarketBillingService() in onServiceConnected .

Because when he completes the binding, he will call back and return IBinder to your connection.

I am 100% sure that this will work!

+1
source

Source: https://habr.com/ru/post/1347369/


All Articles