1

I have been working hard from past two days in implementing google inaapp purchase But its just not working.

Here is my logcat -
07-24 17:23:34.709  11973-11973/com.livebettips D/IabHelper﹕ Starting in-app billing      
setup.
07-24 17:23:34.819  11973-11973/com.livebettips D/IabHelper﹕ Billing service connected.
07-24 17:23:34.819  11973-11973/com.livebettips D/IabHelper﹕ Checking for in-app billing    
3 support.
07-24 17:23:34.869  11857-11863/? D/Finsky﹕ [8] InAppBillingUtils.getPreferredAccount:      
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.879  11973-11973/com.livebettips D/IabHelper﹕ In-app billing version 3    
supported for com.livebettips
07-24 17:23:34.889  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount:      
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.889  11973-11973/com.livebettips D/IabHelper﹕ Subscriptions AVAILABLE.  
07-24 17:23:34.889  11973-11973/com.livebettips D/LiveBetTips﹕ setting up In-app  
Billing: IabResult: Setup successful. (response: 0:OK)
07-24 17:23:34.889  11973-11973/com.livebettips D/IabHelper﹕ Starting async operation:   
refresh inventory
07-24 17:23:34.899  11973-11989/com.livebettips D/IabHelper﹕ Querying owned items, item    
type: inapp
07-24 17:23:34.899  11973-11989/com.livebettips D/IabHelper﹕ Package name:   
com.livebettips
07-24 17:23:34.899  11973-11989/com.livebettips D/IabHelper﹕ Calling getPurchases with 
continuation token: null
07-24 17:23:34.909  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount: 
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.919  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount: 
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.929  11973-11989/com.livebettips D/IabHelper﹕ Owned items response: 0
07-24 17:23:34.929  11973-11989/com.livebettips D/IabHelper﹕ Continuation token: null
07-24 17:23:34.929  11973-11989/com.livebettips D/IabHelper﹕ Querying SKU details.
07-24 17:23:34.939  11857-11863/? D/Finsky﹕ [8] InAppBillingUtils.getPreferredAccount:    
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:34.949  11857-11863/? D/Finsky﹕ [8] InAppBillingUtils.getPreferredAccount:   
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:38.069  11973-11989/com.livebettips D/IabHelper﹕ Querying owned items, item 
type: subs
07-24 17:23:38.069  11973-11989/com.livebettips D/IabHelper﹕ Package name:  
com.livebettips
07-24 17:23:38.069  11973-11989/com.livebettips D/IabHelper﹕ Calling getPurchases with   
continuation token: null
07-24 17:23:38.079  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount:    
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:38.089  11857-11862/? D/Finsky﹕ [7] InAppBillingUtils.getPreferredAccount:    
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]    
07-24 17:23:38.089  11973-11989/com.livebettips D/IabHelper﹕ Owned items response: 0
07-24 17:23:38.089  11973-11989/com.livebettips D/IabHelper﹕ Continuation token: null
07-24 17:23:38.089  11973-11989/com.livebettips D/IabHelper﹕ Querying SKU details.
07-24 17:23:38.099  11857-11988/? D/Finsky﹕ [28] InAppBillingUtils.getPreferredAccount:     
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:38.109  11857-11988/? D/Finsky﹕ [28] InAppBillingUtils.getPreferredAccount:    
com.livebettips: Account from first account - [rm-KEh2jpBdNeb7m7lXeBGgavJ4]
07-24 17:23:39.279  11973-11989/com.livebettips D/IabHelper﹕ Ending async operation: 
refresh inventory
07-24 17:23:39.279  11973-11973/com.livebettips D/result﹕ IabResult: Inventory refresh 
successful. (response: 0:OK)
07-24 17:23:39.279  11973-11973/com.livebettips W/dalvikvm﹕ threadid=1: thread exiting  
with uncaught exception (group=0x40018578)
07-24 17:23:39.289      160-178/? E/﹕ Dumpstate > /data/log/dumpstate_app_error
07-24 17:23:39.289  11973-11973/com.livebettips E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
        at com.livebettips.activities.InAppBilling$2.onQueryInventoryFinished(InAppBilling.java:94)
        at com.livebettips.util.IabHelper$2$1.run(IabHelper.java:630)
        at android.os.Handler.handleCallback(Handler.java:587)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3687)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
        at dalvik.system.NativeStart.main(Native Method)

And here is my code -

   //Google key i got from developer console i split it in 4 parts.key1+key2+key3+key4


    final ArrayList<String> additionalSkuList  = new ArrayList<String>();
    additionalSkuList.add("test2");
    additionalSkuList.add("credit_1");
    additionalSkuList.add("credit_5");

    price = (TextView) findViewById(R.id.tv_inappbilling_price);

    mHelper = new IabHelper(InAppBilling.this,key1+key2+key3+key4);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
            }else{
                Log.d(TAG, "setting up In-app Billing: " + result);

            }
            // Hooray, IAB is fully set up!

            mHelper.queryInventoryAsync(true,additionalSkuList,
                          mQueryFinishedListener);


        }
    });

}

IabHelper.QueryInventoryFinishedListener
        mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory)
    {

        if(mHelper == null){
            Log.d("helper","khatam");
        }

        if (result.isFailure()) {
            // handle error
            return;

        }


        Log.d("result",result.toString());
        if (inventory == null){
           Log.d("inventory",null);
            price.setText("null");
        }else{
            Log.d("inventory",Boolean.toString(inventory.hasDetails("credit_5")));
        }

        String credit_1_Price =
                inventory.getSkuDetails("test2").getSku();    //This is line no 94

        String credit_2_Price =
                inventory.getSkuDetails("credit_5").getPrice();    
        String credit_3_Price =
                inventory.getSkuDetails("credit_1").getPrice();

        price.setText(credit_1_Price+credit_2_Price+credit_3_Price);

        Log.d("Credit 5",credit_2_Price);
        Log.d("Credit 5",credit_3_Price);

        // update the UI
    }
};

I have uploaded the in app products on developer console they are active.

I read that for in app products to be activated i should upload the apk to alpha phase i did that too.

Also do i need to make a purchase first to see the inventory items? I did that too but failed.

Please heeelllpp !

sarthakmeh
  • 90
  • 8
  • are you testing using the installer signed with the same certification using which you signed your alpha installer uploaded to app store? – Rajen Raiyarela Jul 24 '14 at 12:22
  • ya. Same versionCode and same VersionName. – sarthakmeh Jul 24 '14 at 12:26
  • it is okay for versioncode and versionname, requirement is you need to generate an installer using the same certification using which you generated the aplha apk, and then run that installer, as if in debug mode you will not be able to test the application. Also can you pl tell which line of code is line 94? – Rajen Raiyarela Jul 24 '14 at 12:35
  • I have edited my code. Added a comment on line 94.And i am using the same apk. Testind device - Samsung Galaxy ace. – sarthakmeh Jul 24 '14 at 12:39
  • check this recent post accepted solution http://stackoverflow.com/questions/23914789/android-inventory-getskudetails-returning-null – Rajen Raiyarela Jul 24 '14 at 12:55
  • i have read this. As i said in my question my apk is in alpha phase.Still no work. When i change my public key i still get the same response. Do we have to construct the key or just copy the key from developer console and use it? – sarthakmeh Jul 24 '14 at 12:57

1 Answers1

0

Please check whether you have entered right base64EncodedPublicKey and skudetails.

Sanket Sangani
  • 253
  • 3
  • 10