Google InAppBilling onPurchaseStateChange 从未被调用

发布于 2024-10-26 15:54:42 字数 2334 浏览 2 评论 0原文

回调方法 onPurchaseStateChange 永远不会被调用。我做了自己的演示应用程序,并尝试使用谷歌提供的演示(地下城)。

我正在从 onClick 方法调用 requestPurchase(String ProductId, String Payload)


    @Override
    public void onClick(View view) {
        if(view == requestPurchaseButton) {
            mBillingService.requestPurchase("android.test.purchased", "10");
        }
    }

调用回调方法onRequestPurchaseResponse(Request, ResponseCode)。 这里的 responseCode 给出了值 RESULT_OK。这样请求就已经发送到服务器了。


       @Override
       public void onRequestPurchaseResponse(RequestPurchase request,
                ResponseCode responseCode) 
       {
              if(responseCode == ResponseCode.RESULT_OK) {
            Log.d("AJ", "onRequestPurchaseResponse.ResponeCode.RESULT_OK");
            textView.append(request.mProductId + "\n");
          } else if(responseCode == ResponseCode.RESULT_USER_CANCELED) {
                      //doesn't go here
          } else { 
                     //doesn't go here
          }
       }

该方法的 javadoc 指出

当我们收到来自 Market 的针对我们发出的 RequestPurchase 请求的响应代码时,将调用此函数。这不用于任何购买状态更改。所有购买状态更改均在 onPurchaseStateChange(PurchaseState, String, int, long) 中接收。这用于报告各种错误,或者用户退出并没有购买该商品。可能的响应代码有: RESULT_OK 表示订单已成功发送到服务器。当订单被收取或取消时, onPurchaseStateChange() 将在稍后调用(购买状态为 PURCHASED 或 CANCELED)。如果市场管理的商品的订单已发送到服务器,也可能会出现此响应代码。 RESULT_USER_CANCELED 表示用户没有购买该商品。 RESULT_SERVICE_UNAVAILABLE 表示我们无法连接到 Android Market 服务器(例如,如果数据连接断开)。 RESULT_BILLING_UNAVAILABLE 表示尚不支持应用内结算。 RESULT_ITEM_UNAVAILABLE 表示此应用程序出售的商品在服务器端目录中不存在(或未发布)。 RESULT_ERROR 用于任何其他错误(例如服务器错误)。

但回调方法


    @Override
        public void onPurchaseStateChange(PurchaseState purchaseState,
                String itemId, int quantity, long purchaseTime,
                String developerPayload) {
            Log.d("AJ", "onPurchaseStateChanged");

        }

永远不会被调用。

我错过了什么吗? Dungeons 中也做了同样的事情(Google 提供了演示),并且 onPurchaseStateChange 没有被调用。

Test-InAppBilling 文档显示我们必须能够达到已购买状态。但当我尝试时,我只看到

android.test.purchased:发送购买请求。

The call back method onPurchaseStateChange is never called. I did my own demo-app and also tried using the Google provided demo (Dungeons).

I'm calling requestPurchase(String productId, String payload) from the onClick method.


    @Override
    public void onClick(View view) {
        if(view == requestPurchaseButton) {
            mBillingService.requestPurchase("android.test.purchased", "10");
        }
    }

The callback method onRequestPurchaseResponse(Request, ResponseCode) is called.
The responseCode here gives the value RESULT_OK. So the request has been sent to the server.


       @Override
       public void onRequestPurchaseResponse(RequestPurchase request,
                ResponseCode responseCode) 
       {
              if(responseCode == ResponseCode.RESULT_OK) {
            Log.d("AJ", "onRequestPurchaseResponse.ResponeCode.RESULT_OK");
            textView.append(request.mProductId + "\n");
          } else if(responseCode == ResponseCode.RESULT_USER_CANCELED) {
                      //doesn't go here
          } else { 
                     //doesn't go here
          }
       }

The javadoc for this method states

This is called when we receive a response code from Market for a RequestPurchase request that we made. This is NOT used for any purchase state changes. All purchase state changes are received in onPurchaseStateChange(PurchaseState, String, int, long). This is used for reporting various errors, or if the user backed out and didn't purchase the item. The possible response codes are: RESULT_OK means that the order was sent successfully to the server. The onPurchaseStateChange() will be invoked later (with a purchase state of PURCHASED or CANCELED) when the order is charged or canceled. This response code can also happen if an order for a Market-managed item was already sent to the server. RESULT_USER_CANCELED means that the user didn't buy the item. RESULT_SERVICE_UNAVAILABLE means that we couldn't connect to the Android Market server (for example if the data connection is down). RESULT_BILLING_UNAVAILABLE means that in-app billing is not supported yet. RESULT_ITEM_UNAVAILABLE means that the item this app offered for sale does not exist (or is not published) in the server-side catalog. RESULT_ERROR is used for any other errors (such as a server error).

But the callback method


    @Override
        public void onPurchaseStateChange(PurchaseState purchaseState,
                String itemId, int quantity, long purchaseTime,
                String developerPayload) {
            Log.d("AJ", "onPurchaseStateChanged");

        }

is never called.

Am I missing something? The same thing is being done in Dungeons (Google provided demo) and the onPurchaseStateChange is not called.

The Test-InAppBilling document shows that we must be able to reach Purchased state. But When I try, I see only

android.test.purchased: sending purchase request.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2024-11-02 15:54:43

我也遇到了同样的问题,但只是为自己解决了。我在代码中使用了我工作的公钥,但尝试在我的个人手机上运行该应用程序。由于我是用我的个人帐户在手机上登录的,我猜谷歌正确地认为我不是开发者。我认为他们会发回一条错误消息。当我将个人密钥插入代码后,它在我的手机上运行良好。因此密钥可能也不适合您。

I was having this same problem but just solved it for myself. I was using my work's public key in the code, but trying to run the app on my personal phone. Since I was signed in on my phone with my personal account, I'm guessing Google rightly assumed I wasn't the developer. I would think they would send an error message back though. Once I plugged my personal key into the code, it worked fine on my phone. So the key's may not be matching for you as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文