Monday, December 23, 2013

Code to Set Up Billing and Query Inventory

When enabling in-app purchases,the first step is to set up in app billing, the second should be to check to see what upgrades the user has purchased in the past. Here's code from my own app, which was adapted from the Android TrivialDrive sample code:

Initial set-up, (In on create):

        Log.d(TAG, "Starting setup."); //Log that we will start setting up In App Billing (IAB)
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { //Start setup. This is asynchronous and the specified listener will be called once setup completes.
            public void onIabSetupFinished(IabResult result) {
                Log.d(TAG, "Setup finished.");   
                if (!result.isSuccess()) { //If billing setup not a success
                    Log.d(TAG, "Problem setting up in-app billing: " + result);
                if (mHelper == null) return;  // Have we been disposed of in the meantime? If so, quit.
                // if successfullly set up then do this:
                Log.d(TAG, "Setup successful. Querying inventory."); //Log that our setup was successful
                mHelper.queryInventoryAsync(mGotInventoryListener); // Call inventory method of stuff we own

Method for inventory check

    IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
            Log.d(TAG, "Query inventory started"); //Log that were checking inventory 
            if (mHelper == null) return; // Have we been disposed of in the meantime? If so, quit
            if (result.isFailure()) { // Is inventory query a failure?
                Log.d(TAG, "Failed to query inventory: " + result);           
                Toast query = Toast.makeText(Shoulders.this, "Failed to query inventory: " + result, Toast.LENGTH_LONG);
            Log.d(TAG, "Query inventory was successful."); //if query not a failure then log success          
            Purchase premiumPurchase = inventory.getPurchase(SKU_SHOULDERS); // Do we already have the premium upgrade?
            mIsPremium = (premiumPurchase != null);//) && verifyDeveloperPayload(premiumPurchase));
            Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM")); //log if premium or not
            if (mIsPremium) updateUi(); //if we are  premium, show premium upgrade
            Log.d(TAG, "Initial inventory query finished; enabling main UI.");

Tuesday, December 10, 2013

In App Building Tutorial

1.) Add permission to app Manifest file
<uses-permission android:name="" />

2.) Create billing Package in app
Call it and make sure its at /src level, not within your other package

3.) Place IInAppBillingService.aidl file in billing Package
This file is called IInAppBillingService.aidl, downloadable through SDK manager under Extras, and is located in your SDK folder (for me, it was here: \AppData\Local\Android\android-sdk\extras\google\play_billing and you can drag it right into the package in Eclipse)

4.) Create billing utils Package in app
Call it and make sure its at /src level, not within your other packages

5.) Copy all files from the Android TrivialDrive sample app into billing Utils package to help us implement billing
Nine .java files, through, located in a subfolder of Step 3's folder.

6.) Make a button in your app that will allow the user to buy something!

7.) Get your public license key from the App's page in your Developer's Console. It's a long Base64-encoded RSA public key.

8.) Code using those borrowed utils! Examples to follow

Sunday, December 8, 2013

Just released, BodyBuild 1.4 beta. I released this update to 5% of active users for testing. I'm not sure if that means new downloads get 1.4, or the old 1.3. Here are some of the updates:

More leg and arm workouts!
Increased image resolutions
Updated launcher icon
Clickable workout names
Larger muscle diagrams
Formatting issues for workout descriptions fixed
Greater device compatibility
Male and female body builder backgrounds

and coming soon in 1.4 alpha, in app upgrading!

Thursday, December 5, 2013

BodyBuild Update

It has been a while since the great app "BodyBuild" has received an update from Nirmal. Just in time for Christmas, here comes a new version complete with a shiny new launcher icon. More importantly, there are extra workouts.

ImageButton Background

When making an ImageButton, android seems to want to give you a background. To show only your image, and not the background, open up that XML layout and put your image in the src tag:


and then, for the background, toss it a null:


And that should do it. So simple. Don't forget the monkeytail in front of the null!