我目前正在开发游戏,并尝试实施Google Play的应用内结算V3。我按照了应用内样本并使用了IabHelper
。但是,在设备中运行应用程序时出现问题。我发现在mHelper.startSetup
之后,onServiceDisconnected
和onServiceConnected
都没有被召唤。所以我在IabHelper类中打印了mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
的结果。结果是false
。
这是我的代码:
private IabHelper mHelper;
// MainActivity onCreate
protected void onCreate(Bundle savedInstanceState){
// ...
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
return;
}
if (mHelper == null) return;
}
});
}
在IabHelper类的startSetup
方法中:
public void startSetup(final OnIabSetupFinishedListener listener) {
// ...
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
// service available to handle that Intent
boolean bRes = mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
// ### I printed the result here it was false
Log.i("IAB", "IAB Service Result = " + bRes);
}
else {
// no service available to handle that Intent
if (listener != null) {
listener.onIabSetupFinished(
new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device."));
}
}
}
我不知道这个问题。我已经做好了:
有什么想法有什么不对吗?提前致谢。
最后,我通过将最新版本的游戏上传到开发者控制台并调试最新的apk来解决它。问题消失了。希望这有助于某人。
从Project“Trivial”复制util文件夹中的所有类,或者可以将整个Util包复制到项目中。然后尝试一下。
我有这个问题,并发现了