我遵循了在以下位置找到的适用于 android 的应用内计费示例代码:http://developer.android.com/guide/market/billing/billing_integrate.html
我已将该代码集成到我的应用程序中 - 并遵循所有适当的步骤,包括签署 apk - 上传、在应用程序产品列表中创建等。
出于某种原因,当我的应用程序在 onCreate 方法中出现这些行时:
Log.e("sc2","About to check if billing is supported");
// Check if billing is supported.
ResponseHandler.register(mDungeonsPurchaseObserver);
if (!mBillingService.checkBillingSupported()) {
Log.e("sc2","failed check for billing supported");
showDialog(DIALOG_CANNOT_CONNECT_ID);
}
if (!mBillingService.checkBillingSupported(Consts.ITEM_TYPE_SUBSCRIPTION)) {
Log.e("sc2","failed check for billing supported subscriptions");
showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
}
Log.e("sc2","Finished checking if billing is supported");
两个对话框都不显示 - 表明一切都已正确绑定(bind)到市场计费服务。
但是在 PurchaseObserver 回调这些行:
private class SC2PurchaseObserver extends PurchaseObserver {
public SC2PurchaseObserver(Handler handler) {
super(UpgradesActivity.this, handler);
}
@Override
public void onBillingSupported(boolean supported, String type) {
if (Consts.DEBUG) {
Log.e("sc2", "supported: " + supported+":"+type);
}
if (type == null || type.equals(Consts.ITEM_TYPE_INAPP)) {
if (supported) {
restoreDatabase();
mBuyButton.setEnabled(true);
mEditPayloadButton.setEnabled(true);
} else {
showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
}
} else if (type.equals(Consts.ITEM_TYPE_SUBSCRIPTION)) {
mCatalogAdapter.setSubscriptionsSupported(supported);
} else {
showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
}
}
日志消息显示如下:
支持:false:null 支持:false:subs
提示android market回调没有在app billing standard,或者subscription is enabled....
有人可以解释为什么第一次检查可能没有失败 - 但回调消息却像他们那样出现!?
非常感谢
最佳答案
您是否在创建请求包时更改了 BILLING_REQUEST_API_VERSION。以下方法来自示例项目
protected Bundle makeRequestBundle(String method) {
Bundle request = new Bundle();
request.putString(Consts.BILLING_REQUEST_METHOD, method);
request.putInt(Consts.BILLING_REQUEST_API_VERSION, 2);
request.putString(Consts.BILLING_REQUEST_PACKAGE_NAME, getPackageName());
return request;
}
关于Android in app billing 声称不支持使用示例代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11075585/