0

我試圖回到IabHelper.OnIabPurchaseFinishedListener當購買結束我的訂閱,但問題是它沒有調用購買完成後。IabHelper.OnIabPurchaseFinishedListener沒有在應用程序內購買訂閱v3

我曾與onactivity結果試了,但還是它不工作 這裏是我的代碼塊 我延長片段如下

public class ConfirmationScreen extends Fragment { 

mHelper = new IabHelper(getActivity(), base64EncodedPublicKey); 
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { 
    public void onIabSetupFinished(IabResult result) { 
     Log.d(TAG, "Setup finished."); 

     if (!result.isSuccess()) { 
      // Oh noes, there was a problem. 
      complain("Problem setting up in-app billing: " + result); 
      return; 
     } 

     // Have we been disposed of in the meantime? If so, quit. 
     if (mHelper == null) return; 

     // IAB is fully set up. Now, let's get an inventory of stuff we own. 
     Log.d(TAG, "Setup successful. Querying inventory."); 
     // mHelper.queryInventoryAsync(mGotInventoryListener); 
    } 
}); 

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { 
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) { 
     Log.d(TAG, "Query inventory finished."); 
     // Have we been disposed of in the meantime? If so, quit. 
     if (mHelper == null) return; 

     // Is it a failure? 
     if (result.isFailure()) { 
      complain("Failed to query inventory: " + result); 
      return; 
     } 
     Log.d(TAG, "Query inventory was successful."); 

     /* 
     * Check for items we own. Notice that for each purchase, we check 
     * the developer payload to see if it's correct! See 
     * verifyDeveloperPayload(). 
     */ 

     Purchase gasPurchase = inventory.getPurchase(SKU); 
     if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) { 
      Log.d(TAG, "We have gas. Consuming it."); 
      mHelper.consumeAsync(inventory.getPurchase(SKU), mConsumeFinishedListener); 
      return; 
     } 
    } 
}; 

//Callback for when a purchase is finished 
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { 
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) { 
     Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase); 
     // if we were disposed of in the meantime, quit. 
     if (mHelper == null) return; 
     Log.d(TAG, "Purchase successful."); 
     if (purchase.getSku().equals(SKU)) { 
      //bought 1/4 tank of gas. So consume it. 
      Log.d(TAG, "Purchase is gas. Starting gas consumption."); 
     } 
    } 
}; 

我已經提到this鏈接

回答

3

您需要實現您的onActivityResult方法FragmentActivity

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // Pass on the activity result to the helper for handling 
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) { 
     // not handled, so handle it ourselves (here's where you'd 
     // perform any handling of activity results not related to in-app 
     // billing... 
     super.onActivityResult(requestCode, resultCode, data); 
    } else { 
     Log.d(TAG, "onActivityResult handled by IABUtil."); 
    } 
} 
+0

也許你需要重寫它的主要活動 – 2015-06-09 18:05:15

0

您需要實現您FragmentActivity

這已經被投入在活動,這實際運行的onActivityResult方法:

mHelper.launchPurchaseFlow(...); 
相關問題