Trying to add some in app purchasing to an app I'm working on but things aren't going to so well.
I've got a FragmentActivity like this:
public class TestInAppBilling extends FragmentActivity{
//Application context reference
private static Context context;
/*
Billing stuff
*/
private IInAppBillingService mService;
private ServiceConnection mServiceConn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_layout);
context = getApplicationContext();
if(mServiceConn == null){
mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
System.out.println("Bound!");
}
};
context.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mServiceConn != null) {
unbindService(mServiceConn);
}
}
}
But for some reason the onServiceConnected callback never happens.
Anyone know whats causing it?
I think that you solved it. Anyway I had the same problem and I just fixed it. To make it work delete this line:
context.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);
And add this:
setContentView(R.layout.test_layout);
context = getApplicationContext();
Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
intent.setPackage("com.android.vending");
getContext().bindService(intent, mServiceConn, getActivity().BIND_AUTO_CREATE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With