2013-08-02 5 views
10

सेट अप नहीं किया गया है, मैं ऐप बिलिंग में लागू करने की कोशिश कर रहा हूं। मैंने trivialdrivesample का उपयोग किया है जैसा कि यह है।ऐप बिलिंग में आईएबी सेटअप सफल लेकिन quaryInventory रिपोर्ट आईएबी हेल्पर

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // load game data 
    loadData(); 


    String base64EncodedPublicKey = "my key"; 



    // Create the helper, passing it our context and the public key to verify signatures with 
    Log.d(TAG, "Creating IAB helper."); 
    mHelper = new IabHelper(this, base64EncodedPublicKey); 

    // enable debug logging (for a production application, you should set this to false). 
    mHelper.enableDebugLogging(true); 

    // Start setup. This is asynchronous and the specified listener 
    // will be called once setup completes. 
    Log.d(TAG, "Starting setup."); 
    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; 
      } 

      // Hooray, 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); 
     } 
    }); 
} 

Button purchaseB = (Button)findViewById(R.id.purchase_button); 

if(purchaseB != null) 
    purchaseB.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 

     onUpgradeAppButtonClicked(null); 

     } 
    }); 

इसकी पूरी तरह से काम कर रहा है और मैं अपने परीक्षण खाते से खरीद करने के लिए कर रहा हूँ।

लेकिन समस्या यह है कि मैं टिप्पणी करने के लिए कोड लाइन है कि है

// mHelper.queryInventoryAsync (mGotInventoryListener); इसलिए मैं सूची क्वेरी करने में सक्षम नहीं हूं। डबगिंग पर मैंने पाया कि वेरिएबल

// Is setup done? 
    boolean mSetupDone = false; 

IabHelper क्लास में झूठा है और यह अपवाद उठाता है। सेटअप कहने के ठीक बाद लॉग इन कह रहा है कि आईएबी सहायक स्थापित नहीं है।


08-02 16:02:42.453: D/PackList(10346): Creating IAB helper. 
08-02 16:02:42.453: D/PackList(10346): Starting setup. 
08-02 16:02:42.468: D/IabHelper(10346): Starting in-app billing setup. 
08-02 16:02:42.515: D/PackList(10346): Creating IAB helper. 
08-02 16:02:42.539: D/IabHelper(10346): Billing service connected. 
08-02 16:02:42.546: D/IabHelper(10346): Checking for in-app billing 3 support. 
08-02 16:02:42.562: D/IabHelper(10346): In-app billing version 3 supported for com.xx 
08-02 16:02:42.570: D/IabHelper(10346): Subscriptions AVAILABLE. 
08-02 16:02:42.570: D/PackList(10346): Setup finished. 
08-02 16:02:42.570: D/PackList(10346): Setup successful. Querying inventory. 
08-02 16:02:42.578: E/IabHelper(10346): In-app billing error: Illegal state for operation (queryInventory): IAB helper is not set up. 
+0

इस जवाब देखें: http://stackoverflow.com/questions/17944522/google-in-app-billing -कॉसिंग-अपवाद/17 9 60318 # 17 9 60318 – Carl

+0

इसे भी देखें http://stackoverflow.com/a/13981478/2106820 –

उत्तर

0

इस प्रयास करें।

की स्थापना:

mIabHelper = new IabHelper(this, ProjectKonstants.APP_PUBLIC_KEY_GOOGLE_PLAY); 

mIabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() 
{ 
    public void onIabSetupFinished(IabResult result) 
    { 
     if (result.isSuccess()) 
     { 
      mIabHelper.queryInventoryAsync(mInitialInventoryListener); 
     } 
    } 
}); 

mInitialInventoryListener = new IabHelper.QueryInventoryFinishedListener() 
{ 
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) 
    { 
     if (result.isSuccess()) 
     { 
      mBHasDonated = inventory.hasPurchase(ProjectKonstants.APPLICATION_SKU_FOR_DONATION); 
     } 
     else 
     { 
      mBHasDonated = false; 
     } 
    } 
}; 

mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() 
{ 
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) 
    { 
     if (result.isSuccess()) 
     { 
      if (purchase.getSku().equals(ProjectKonstants.APPLICATION_SKU_FOR_DONATION)) 
      { 
       mBHasDonated = true; 
       return; 
      } 
     } 
     mBHasDonated = false; 
    } 
}; 

अपग्रेड बटन पर क्लिक किया:

AccountManager accountManager = (AccountManager) getSystemService(ACCOUNT_SERVICE); 
Account[] accounts = accountManager.getAccounts(); 
String strIdentifier = "[" + accounts[0].name + "][" + android.os.Build.MODEL + "][" + android.os.Build.VERSION.RELEASE + "]"; 
try 
{ 
    mIabHelper.launchPurchaseFlow(this, ProjectKonstants.APPLICATION_SKU_FOR_DONATION, 10001, mPurchaseFinishedListener, strIdentifier); 
} 
catch (IllegalStateException e) 
{ 
} 
संबंधित मुद्दे