谷歌InAppBilling onPurchaseStateChange不会被调用谷歌、InAppBilling、onPurchaseStateChange

2023-09-05 09:30:02 作者:讨喜冤家

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

我打电话 requestPurchase(字符串productId参数,字符串有效载荷)的onClick 方法。

 
    @覆盖
    公共无效的onClick(视图查看){
        如果(查看== requestPurchaseButton){
            mBillingService.requestPurchase(android.test.purchased,10);
        }
    }
 

回调方法 onRequestPurchaseResponse(请求,响应code)被调用。 该响应code 这里给出的值 RESULT_OK 。所以该请求已被发送到服务器。

 
       @覆盖
       公共无效onRequestPurchaseResponse(RequestPurchase要求,
                响应code响应code)
       {
              如果(响应code == C $ c.RESULT_OK响应$){
            Log.d(AJ,onRequestPurchaseResponse.Respone code.RESULT_OK);
            textView.append(request.mProductId +\ N);
          }否则,如果(响应code == C $ c.RESULT_USER_CANCELED响应$){
                      //不走这里
          } 其他 {
                     //不走这里
          }
       }

 

的javadoc这种方法状态

  

此,当我们收到来自市场的响应$ C $下,我们做了一个RequestPurchase请求调用。这是不是用于购买任何状态变化。所有购买状态变化都收到onPurchaseStateChange(PurchaseState,字符串的int,long)。这种用于报告各种错误,或者如果用户退出了,并没有购买该物品。可能的响应codeS是:RESULT_OK意味着该顺序被成功发送到服务器。该onPurchaseStateChange()将在以后调用(以购买或取消了购买状态)时,为了充电或取消。这个响应code也可能发生,如果为一个市场管理项目的命令已经发送到服务器。 RESULT_USER_CANCELED意味着用户没有购买该项目。 RESULT_SERVICE_UNAVAILABLE意味着我们无法连接到Android Market的服务器(例如,如果数据连接已断开)。 RESULT_BILLING_UNAVAILABLE意味着,在应用程序不支持计费呢。 RESULT_ITEM_UNAVAILABLE意味着项目这个程序出售不存在(或不公布),在服务器端目录。 RESULT_ERROR用于任何其他错误(如服务器错误)。

但回调方法

 
    @覆盖
        公共无效onPurchaseStateChange(PurchaseState purchaseState,
                字符串的itemId,INT量,长purchaseTime,
                字符串developerPayload){
            Log.d(AJ,onPurchaseStateChanged);

        }
 

永远不会被调用。

我缺少的东西?同样的事情在地下城正在做(谷歌提供的演示)和 onPurchaseStateChange 不叫。

借助试验InAppBilling 的文件显示,我们必须能够达到购买状态。但是,当我尝试,我只看到

  

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

解决方案

我有同样的问题,但只是解决了它自己。我用了code我的工作的公开密钥,但试图运行我个人的手机应用程序。由于我签署了我的手机上有我的个人账户,我猜谷歌恰当地认为我是不是开发商。我想他们会发送一个错误信息回不过。有一次,我插我个人的钥匙插入code,它工作得很好我的电话。因此,关键的可能不匹配的你。

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.

解决方案

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.