In billing apps in android

I am using the 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 also added IMarketBillingService.aidl , but still it looks like:

Failed to associate with MarketBillingService

Can you point out my mistake?

+4
source share
2 answers

I don't know if this is the cause of your problem, but you are using bindService () in getBaseContext (). Is there a reason why you are not calling bindService () on the service instance? This is what the sample service does.

The basic context seems to be mostly unnecessary, and the general advice does not seem to use it. See Another question: What is the difference between the various methods for obtaining context?

In addition, the latest (or at least recent) version of the Android Market app should be installed on your device, although I assume that it is being updated.

There is a way to check if the application in the In-App Billing market supports something described in the In-App-Billing link. I guess it's worth doing this check.

0
source

I tested an old Android device with a clean system. It did not have a copy of the Google Market app (hat tip @sstn).

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

Then I uninstalled and reinstalled my application, and it is correctly tied to the service!

0
source

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


All Articles