gpt4 book ai didi

Android InAppBilling onServiceConnected 从未调用过

转载 作者:太空狗 更新时间:2023-10-29 14:20:42 27 4
gpt4 key购买 nike

我正在尝试将一些应用内购买添加到我正在开发的应用中,但进展并不顺利。

我有一个像这样的 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 回调从未发生。

有人知道是什么原因造成的吗?

最佳答案

我想你已经解决了。无论如何,我遇到了同样的问题,我只是解决了它。要使其正常工作,请删除此行:

context.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);

然后添加:

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);

关于Android InAppBilling onServiceConnected 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17204594/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com