2

我遵循了在以下位置找到的 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");

两个对话框都没有显示 - 表明所有内容都正确绑定到市场计费服务。

但是在 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 回调在应用计费标准中没有说明,也没有启用订阅....

有人可以解释为什么第一次检查可能没有失败 - 但回叫消息却像他们一样出现!?

非常感谢

4

2 回答 2

13

这是我使用的代码Simple InApp Billing / Payment,您也可以使用。

在此处输入图像描述

在此处输入图像描述

希望能帮助到你。

于 2012-06-20T11:57:35.033 回答
0

创建请求包时是否更改了 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;
}
于 2012-07-27T10:50:00.233 回答