尝试将一些应用内购买添加到我正在开发的应用中,但事情不会那么顺利。
我有这样的 FragmentActivity:
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);
}
}
}
但由于某种原因,onServiceConnected 回调永远不会发生。
有谁知道是什么原因造成的?