Showing posts with label Google Play Services. Show all posts
Showing posts with label Google Play Services. Show all posts

Monday, March 31, 2014

Android Programming With the Google+ API Overview

Since its launch in 2011 Google+ has gained a reputation and following that seems to be growing by leaps and bounds. As more traffic jumps on the Google+ bandwagon; more and more developers are looking for ways to incorporate Google+ functionality into their apps.

This article discusses concepts and tools associated with developing Android applications that use the Google+ API to: 
  • Present Google+ log-in and Consent Form to users;
  • Create Google+ posts;
  • Access and use user activity data (such as game scores, purchases, etc.); and
  • Search and retrieve Google+ people information (for example, listing people with the highest game scores, etc).
It also discusses the Google Play Services public interfaces associated with the Android Quick Start app.

Getting Started


To develop an Android application on the Google+ platform you will need Google Play Services and the latest version of the SDK Tools, which can be added or updated using the Android SDK Manager.

The Android SDK Manager can be accessed from within the Eclipse IDE (with the Android Development Tools) by selecting Window -> Android SDK Manager. You can then select to install or update Google Play Services and the SDK Tools, as shown in the following picture. For more information see my previous article Programming Mobile Apps for Android With Eclipse and Getting Started With the Google+ Platform.


Note that you may even need to update the Android Developer Tools (ADT) plugin if you are using Eclipse to build Android apps. If you need to update the ADT you can do so (from within Eclipse) by selecting  Help -> Install New Software. The Available Software window displays. When you click the Add button the Add Repository window (shown below) displays. You can then add the URL for the ADT: https://dl-ssl.google.com/android/eclipse/


Once you add the URL and click OK the wizard walks you through selecting the components you can install to update an existing installation.


For additional information on updating the ADT in Eclipse visit  http://developer.android.com/sdk/installing/installing-adt.html.

Installing or updating Google Play Services, SDK tools, ADT, are just a few of the updates you may need to make to your development environment. For a complete list of the prerequisites needed to use the Google+ API you can visit: https://developers.google.com/+/mobile/android/getting-started#prerequisites.

Google Developers Console

Once you have prepared your development environment as previously mentioned, you need to enable the Google+ API. To begin you access the Google Developers Console and create a project. The Console automatically assigns a unique project name.


Once the project is created you can select the project to set the properties.


In this example I created a project to run the Google Quick Start sample project. I can now enable the Google+ API by clicking the Off button to turn On the Google+ API.

You will also need a unique Client ID, which is created by clicking the Create New Client ID button shown in the following picture. The Create Client ID window, also shown below, displays. You will then need to add the application type (which is "Installed" for Android apps) and package name (I used: com.google.android.gms.plus.sample.quickstart as the package name so I could run the Quick Start Sample). You will also need the Signing certificate fingerprint (SHA1) (see my previous article How to Build Facebook Apps and Games for Android to learn more about hash keys). Once all fields are completed you can save your changes. 



Once the information has been entered and submitted the client ID is created, as shown in the following picture. In this example the client ID is associated with the package name of the application (shown in the following picture). Therefore, if you add a package name that is different from that of the package name in the application your sample application will not work.



As API requests are sent, from your application, to the Google Server the client ID is used to identify your application and also track associated transactions.


After you enable the Google+ API (application programming interface) you can configure your development environment to make Google+ API calls via Google Play Services.

Once you create your project in the Google Developers Console you must then clone or download the sample application from GitHub:  https://github.com/googleplus/gplus-quickstart-android.

Configuring the Android Quick Start App

As previously mentioned, your project will use Google Play Services to access the Google+ API. Therefore, part of preparing your development environment includes importing the Google Play Services library located in the adt-bundle directory on your computer. (Note: I'm running Windows 64-bit so my adt-bundle directory is as follows:  adt-bundle-windows-x86_64-20131030). The path to the Google Play Services library on my computer is as follows:


Use File -> Import from within the Eclipse IDE to select the Google Play Services Library project.
Select the Google Play Services lib project, as shown below. Click Finish to import the selected project.

You will then need to reference the google-play-services_lib project from within your project.  To run the sample I must first reference google-play-services_lib.To do this I right-clicked the project and select properties from the menu to display the Project Properties window, shown below.


I can then click the Add button and select the google-play-services_lib (which is available because you added it as a project to the workspace).


Once you have added the project you can click OK to close the Project Properties window.



To run the sample you must connect to a real Android device. Since your project is not configured to run on a specific device (real or virtual) when you select Run, from within the Eclipse IDE, the Android Device Chooser displays (as shown below).


I can then click OK to run the device. For more information about running virtual versus real devices see my previous article titled, Programming Mobile Apps for Android With Eclipse.

OAuth 2.0 Protocol


The Google+ authentication/authorization uses the OAuth 2.0 framework. The OAuth 2.0 framework was created so third-party applications could access another company's resources (mainly social networking company resources) without giving these applications customer's private data.

With the OAuth 2.0 Framework a users' log-in, for example, is neither accessed nor stored by a third-party app. And, Google is just one of many companies that currently use the OAuth 2.0 Framework.Google's implementation of the OAuth 2.0 framework supports three types of applications: Web Server apps, computer and hand-held device apps and apps that run on the client-side (such as JavaScript applications).

To implement the Google+ login, which utilizes the OAuth 2.0 framework for authentication and authorization, developers can use Google+ log-in, which invokes the user Consent Form as well as the Google user login window.


API programming really is all about code re-use, which makes developing apps easier and faster. Consider the development time cut by building an application on top of one or more existing applications (in this case Google+ and Google Play Services). You do not have to write as much code to build your application. Instead, you use your knowledge of the existing applications (by reviewing the API documentation) and then declaring variables/objects and calling the methods, etc. you want to use or setting the applicable properties to fit your application. Notice below the code to import the Login button and then the code that declares and calls the Login button. A procedure was not written to create the Login button because it already exists.



When the user click the Google+ Sign in button the user is presented with the Google sign-in. To login the user enters the correct user name and password and submits the response. The Consent form is also presented to the user. The user reviews the form and makes desired changes to the Consent form if the application requests access the user does not want to give. The information is sent to Google Play Services. If the credentials are accurate the Google server returns an authorization code to your application. Your application then requests an access token. The Google server returns an access token to your application.




The access token is used, by your application, to perform the approved transactions on behalf of the user. The response from the server also includes a refresh token. Whenever the access token expires the refresh token is used to request a new access token until the refresh token expires. For more information on OAuth 2.0 see Google's OAuth 2.0 Playground . For more on Google+ sign in for Android see: https://developers.google.com/+/mobile/android/sign-in and https://developers.google.com/+/features/sign-in

Google Play Services & The Google+ API


In the Quick Start app, the googleapiclient is the "main entrypoint for Google Play Services integration" so that calls from the application to Google Play are wrapped with the googleapiclient interface.  Once a connection is established the People class is used to get information associated the current person logged in. The Quick Start app calls the AccountAPI to clear the default account or revoke access when the user selects the applicable option. The following paragraphs provide additional information about the Google+ API.

The Google+ API is divided into four resource types as follows:  People, Activities, Comments and Moments

People Resource: The People resource contains the method used to get people data by retrieving the individual's user name  (or userID). A few of the properties associated with the People resource include the person's name, profile image, profile URL, about me content (including the about me description, bragging rights, relationship status), organization where the person works/worked, places lived, circled-by count, plus-one count, whether or not the account is verified, the cover photo and more. Developers can incorporate some or all of the attributes within an application that uses the Google+ API. The developer can also use the People resource to search for people, list people by activity (discussed below), etc.


Activities Resource: The Activities resource is used to work with content posted to Google+. The Activities resource has three property types as follows: Actor, Object and Verb. The Actor property type includes properties associated with the person who performs an activity such as create a post, re-share a post or even plus-one a post. A few Actor properties include display name, the URL for the person's profile, the URL for the person's profile image, etc.The Verb property type defines whether content was created (i.e., newly published content) or re-shared. The Object property includes properties such as the object type for example whether the activity is associated with content or an action such as plus-one or re-share.It also includes properties that hold the ID of the object, the original actor, comments (or replies) associated with the published content, people who +1'd the content, etc.

Comments Resource: The Comments resource includes methods used to list comments associated with content or get content.

Moments Resource: The Moments resource includes methods used to record activities users perform.For example, if a user makes a purchase or achieves a high score in a game; developers can use the moments.insert method to create a post that discloses the applicable information.

Lastly, developers use App Activities to create actions users can perform within an application such as buying, adding comments, identifying the user's location, etc.

Thursday, August 8, 2013

Mobile Software Programming: Designing & Building Mobile Apps (Android)

We've all heard the Nick D'Aloisio's story right? He's the British high school student who built and sold a mobile news app to Yahoo for $30 million earlier this year. He is just one of many developers who have learned they can make good money developing mobile apps--particularly ones that add value to social networking apps. This blog article presents an overview of software design and programming associated with one of our biggest passions "the mobile phone".

Introduction


Software development for mobile devices refers to developing software for a mobile phone, tablet or other handheld device. Within the Information Technology community mobile phone development is part of the telecommunications (or telecom) industry.

When we pick up a mobile phone to make a call we are holding hardware manufactured by Motorola, Apple, Nexus, Samsung, LG Corporation or some other corp. The phone has an operating system (OS) and additional apps so you can make calls, store phone numbers, add calendar appointments, etc. The OS might be Android built by Google. Or, you may have a phone running Windows by Microsoft; or, even a iPhone running iOS by Apple. When you install applications on a phone you select applications that are compatible with the phone's OS. 

Ever stop to wonder why you can't use a Verizon phone on a Sprint network? When Google, Microsoft or other software development company develops a mobile OS that company does not customize the OS for one or more networks (such as Verizon, AT&T, Sprint, etc.).  Instead Verizon, AT&T, Sprint and other telecommunication companies hire software developers to customize the mobile OS so the phone connects to and communicates with their network. I had an opportunity to support a software development project at Nextel, before it was acquired by Sprint. It was an amazing, insightful opportunity.



There are three types of apps that can be developed for the mobile phone: 1. Mobile version of a web application; 2. A mobile business or other non-game application; and 3. a mobile game application.

Mobile Version of a Web Application


Often companies want software developers to build a web application, which is installed on a web server and accessed using a web browser. These developers are often tasked with building a mobile version of the web application. When building a mobile version of a web app a phone's OS isn't considered. This is because the user will use the phone's browser to access the mobile version of the web app. Consider the following blog site.


Following is the mobile version for the same page shown above. Notice the image is gone and the navigation has changed. Since this is a blog app a "categories" drop-down is added so users can select a category and clicks the Refresh button. The page then displays a list of articles associated with the selected category. The links have been added so the user can navigate to the details stored on a separate page. Content on a mobile page is typically limited so the page loads quickly.


The following picture shows the page the user was directed to after clicking the "Day 1 Class Notes - 7th Grade English... link on the above page.


The mobile version of a website or web application is designed to be intuitively; and, enable users to easily access information. In addition, images may be removed, especially if they are large, so loading pictures doesn't slow down the page load. Lastly, header and footer designs are either simplified or not shown on a mobile version of the site or web app.

Mobile Application Design


The a key different between developing a mobile web app versus a mobile app or mobile game app. The key difference is the non-web mobile app or mobile game is developed to be installed directly onto a mobile device. Therefore, the mobile phone's operating system is a consideration when developing a non-web mobile app or mobile game.

There are various aspects to designing a mobile app including the application structure. Every mobile app (including games) include a top Level page (also referred to as the Start Screen). The Start Screen is the page the user sees when first accessing the application. The Start Screen for mobile apps have an action bar (that includes the app's icon or title). The action bar may include a button to create content; and,t it may also include a search icon so users can search content. The Start Screen may include tabs or other ways to navigate through various views of the data. Mobile apps built to manage data also include category views and detail/edit views.  Let's look at the design of a couple of Android apps.

Consider Google's Blogger application (or app) used to manage blog articles. Notice the action bar at the top includes the icon and the app title. The pencil is the button used to create a new post unless the checkbox beside a post is selected.  In that case the pencil is the button used to display the edit post page view. In addition three tabs are displayed so the articles can be grouped using the following categories:  All, Published or Draft. This means users can view all articles; only published articles; or, articles for which a draft has been created. In the following picture the Published category is selected.


Notice the top level page includes a list of articles that shows us the title of the article, the keywords associated with the article and the date the article was published. The user clicks on an article to view the article details.  (Note that Google's Blogger can be accessed using the mobile phone's browser; or, users can download and install Google's Blogger mobile app from Google Play.)

Consider the Calendar mobile app used to manage events or appointments. The action bar at the top of the page includes the month and year. It also includes a menu so users can select a view as follows: Day, Week, Month or Agenda. And, the action bar has a button that allows the user to create a new event. The top level page also has tabs that include the same options as the action bar menu. If the user selects week the user can view all events for the week. Or, if the user selects Agenda the user views a list of all events. From any of these views the user clicks on an event to view the details pages that contains detailed information for the event.

Twitter's action bar includes the Twitter icon, the tab selected (in the following page Me is the tab select). Also notice you can search content or create a new tweet from the action bar. The top level page displays profile information that spans 2 pages. The tweets, # of followers and # following of people following you are also included. In addition, only the first few tweets are loaded when the page displays. This approach ensures users don't have to wait too long to view the top level page. Notice the Home, Connect, Discover and Me options are available from the top level page. As previously mentioned, the following capture shows the Me option selected.

The mobile music app presents an example of how the top level can offer users a number different views to present the same data. For example, the Songs view lists each individual song (and yes I do listen to Christmas music all year despite my daughter's complaints). The Artists view groups songs by artist. Notice in the following picture I have songs from three Take 6 albums. The music app groups all of the Take 6 albums under one artist and displays the picture for each album. Users click the button with a circle and arrow to expand or collapse the items listed under an artist. The Albums view groups the songs by album. And, the Playlist view groups songs by favorites, most played, recently played, and recently added.


When the phone is turned landscape the app automatically displays the album image for every album. The title of the album playing scrolls across the bottom of the album image.



Notice, most mobile applications follow a design concept that focuses on making user access intuitive and simple. In every example, the mobile application is designed so users spend more time using the app and less time learning "how to" use the app. To learn more about designing mobile apps view Google's Design page for mobile apps.

A Non-game Mobile Application


Android applications are created using Java, which is one of two popular programming languages used by businesses across the country. Android is a multi-user system in that each application is treated like a different user; and, each application is automatically assigned a unique user ID when it is installed. Also, once installed, the Android app resides in its own security sandbox. And, the system ensures each app only performs the actions its permissions allow it to perform based on selections made by the user during the installation process.


Building Your Development Environment


Mobile app programming can be interesting and fun--especially for those who spend hours on the computer. Prior to building an Android app you have to configure your computer (or laptop) to serve as a development environment. This includes downloading and installing the Android SDK - ADT Bundle for Windows or other platforms.



Once you download the ADT Bundle you end up with a zipped file called:  adt-bundle-windows-x86-20130729.zip (unless you download the 64 bit for Windows or version for a different operating system). You will need to add a new folder to your computer and then extract the contents of this file to the new folder you created. When you navigate to the extracted files you will see the SDK Manager.exe.


You can double-click the SDK Manager.exe to install the Android SDK tools including the Eclipse plugin, Android app samples and more.


Once you have installed the Android SDK you can launch Eclipse by navigating to the folder you created and then exploring the contents of the Eclipse folder. Locate and double-click on the Eclipse.exe file to launch the Eclipse development environment.



The Android Developer Tools splash screen displays, as shown below.



Next, the Eclipse Integrated Development Environment (IDE) displays. You can then create a project and begin developing Android apps.



Once you have reviewed the Android App Fundamentals you can use the Training link to learn how to build your first Android App. The training presents the steps on how to create a project, build a simple user interface and more. The best rule of thumb is to following the trainings to learn how to build an Android app. Once you are successful at following the trainings and you understand how the training apps are developed; you can then practice building small apps to become experienced in building custom apps. Most importantly, don't expect to conquer the Android app world overnight.

After you have finished developing your app you will want to test your app. The Android framework includes an integrated testing framework so you can test your application. In addition, the Android SDK includes tools that enable you to setup and run your test applications. Once you have completed testing you are ready to learn about distributing  your app.

Next, you'll want to follow the steps necessary to publish your Android app to Google Play, which is the tool Android users turn to to pay for, download, and install mobile apps. To publish your app to Google Play you must become a registered developer. This is part of the process required to "Register for a publisher account". Be prepared to pay the $25.00 registration fee. This process will enable you to publish your Android app to Google Play and make it available to your target audience.



Whether you are just getting started with Android development; or, you have some experience you may enjoy your development experience more if you join a development community.  Or, if you want to become an Android developer; but you are a bit nervous join a development community and read about other's experiences. Development communities share information. This approach gives you access to fellow developers with whom you can share problems and gain insight, etc. There are several communities that you may find useful. A few of these communities are listed in the following paragraphs.

The first community is  XDA Developers, which is a software development community that focuses solely on mobile technologies. The community includes over five million users and the group shares tips, helps troubleshoot problems and more.  XDA Developers enables users to view and download content as a guest. However, to post comments you must register. XDA Developers can be accessed by navigating to http://forum.xda-developers.com/ .  XDA also have an XDA TV channel that presents very useful information. The Register button is located in the far right corner of the page as shown below.


You can also join Google's Android Developer group at https://groups.google.com/forum/#!forum/android-developers . Android Community is also another choice. Android Community is an open-source project community led by Google. You can learn more about the Community by visiting the following link: http://source.android.com/index.html .

A Mobile Game Application

Game developers can use Google Play game services, and their imagination, to building interactive, addictive games.


Game developers can also incorporate achievements that unlock new game capabilities once a player obtains a number of points defined by the game developer. 


The achievements can be tied to levels (i.e., a player completes level 1 after earning 100 points, which then unlocks level 2). Or, developers can tie achievements to game capabilities. For example, with the game Plants vs Zombies players must reach a certain level in the Adventure part of the game to unlock the Quick Play functionality.




Another very useful option that can be added to games is Cloud Save. Developers can incorporate the Cloud Save service so players can play a game across multiple devices. For example, while in the car a child may play a game using a mobile phone. Once the child gets home he can go to a computer and pick up where he left off by playing the web version of the game. Cloud Save enables data to be synchronized across multiple devices so the player never looses progress as he moves from one device to another.

Games can also include a capability called leaderboards, which can be used to up the stakes by allowing players to compare their score to previous game scores; or, top scores from other players. When the developer creates a leaderboard for a game the developer programs the leaderboard to submit the score to one or more leaderboards at the end of a game.

At the end of each game the game checks to see if the player's score is better than a previous score, which can be compared to daily scores, weekly scores or all-time high scores. The game will always update the leaderboard with the best score so the player (or other plays) can see how good a player is at the game.

Games can also be built to support multiple players (referred to as multiplayer games). For example, the real-time multiplayer game can be developed to include participants and a virtual meeting room, used as the game space. Games can be designed so that a player can invite other players to the virtual meeting room. Players who accept the invitation are joined to the meeting room. Or, the game can be designed to automatically match players to a meeting room based on preferences stated by the player.

Lastly, with Google Play game services game developers can build games so players can sign into the game using their Google+ account. Users can play other Google+ players by accessing multiplayer mode on the mobile game. Game players can even compete with one another and compare scores. In addition, developers can add a Google+ Share button so players can post tips, progress and other information about the application right to their Google+ wall from within the game--adding the power of social networking to a player's experience. Like non-game applications, Android game applications must be published. Games are published  to Google Play Game Services and to Google Play.

Future posts will include more details on mobile programming and programming for the Amazon Kindle (which is pretty hot right now).

This article has discussed a few of the capabilities available to game developers. Note that there is an interesting video about game development at:  https://developers.google.com/events/io/sessions/326367481. The video is hosted by Dan Galpin, who is a Developer Advocate; Jaewoong Jung, who is a software engineer that builds games; and Jennie Lees, who is a product manager.

For More Information


The following links provide access to trainings, tutorials and additional information you may find useful in your endeavor to become an Android app developer, Android game developer or both: