I'm trying to implement In App Billing use the reference from here
I followed the instructions, but ran into trouble binding the InAppBillingService. It would seem that my ServiceConnection's onServiceConnected(...) method never gets called, and that method is responsible for creating my InAppBillingService Interface.
Furthermore, context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE) returns false every time, indicating some sort of problem. Maybe InAppBilling isnt available for some reason, isBillingSupported(...) is returning false. I am not using an emulator.
Here is my class :
public class GoogleShop extends Shop {
private ServiceConnection serviceConnection;
private IInAppBillingService service;
public GoogleShop() {
this.serviceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
service = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
service = IInAppBillingService.Stub.asInterface(binder);
}
};
}
public void bindService(Context context) {
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
System.out.println("InAppBillingAvailable : " + GoogleShop.isBillingAvailable(context));
if (context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE))
return;
else
throw new RuntimeException("BindService returned false");
}
public ServiceConnection service() {
return serviceConnection;
}
public static boolean isBillingAvailable(Context context) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
List<ResolveInfo> list = packageManager.queryIntentServices(intent, 0);
return list.size() > 0;
}
}
Also, I didn't forget to add
<uses-permission android:name="com.android.vending.BILLING" />
to my Manifest
You are doing it the hard way. See this Google guide for preparing in app billing. Google has an open source class, called the IabHelper which handles Iab for you and has seen a number of iterations already, so it will be superior to what you are creating now.
Also you can see this code.google link