如何在android.test.purchased购买项目后获得响应

时间:2013-05-16 07:36:07

标签: android in-app-purchase in-app-billing

我使用结算方式进行新的应用内购买 我有Billing Helper和Billing Receiver类 如何从Billing Helper或Billing Receiver购买物品后获取响应代码 谢谢。

2 个答案:

答案 0 :(得分:3)

在启动购买流程时传入的OnIabPurchaseFinishedListener

mIabHelper.launchPurchaseFlow(this, SKU_TEST_PURCHASED, TEST_PURCHASED_REQUEST_CODE, mPurchaseFinishedListener, developerPayload);

以下是示例代码

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() 
    {

        @Override
        public void onIabPurchaseFinished(IabResult result, Purchase info) 
        {
             Log.d("onIabPurchaseFinished", "Purchase finished: " + result + ", purchase: " + info);
             if(result.isFailure())
             {
                 complain("Error purchasing: " + result);

                 return;
             }

             Log.d("onIabPurchaseFinished", "Purchase successful.");

             if(info.getSku().equals("android.test.purchased"))
             {
                 Log.d("onIabPurchaseFinished", "Purchase is android.test.purchased");

                 mIabHelper.consumeAsync(info, mConsumeFinishedListener);
             }
        }
    };

答案 1 :(得分:0)

我从https://codeload.github.com/blundell/SimpleInAppPurchaseV3/zip/master

下载了代码
 @Override
         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
             super.onActivityResult(requestCode, resultCode, data);
             if (Navigator.REQUEST_PASSPORT_PURCHASE == requestCode) {
                 if (RESULT_OK == resultCode) {
                     dealWithSuccessfulPurchase();
                 } else {
                     dealWithFailedPurchase();
                 }
             }
         }

         private void dealWithSuccessfulPurchase() {
             Log.d("Passport purchased","Passport purchased");
             popToast("Passport purchased");

         }

         private void dealWithFailedPurchase() {
             Log.d("Passport purchase failed","Passport purchase failed");
             popToast("Failed to purchase passport");
         }