Android game development or any other smartphone game development is not complete without implementing background services. Background services help the game spread and perform to reach the next level.
The style of game development has changed a lot with time. New styles and monetization techniques have been introduced. New game services have been created to support these techniques. Many tech companies start their own services to create a new industry. Any work we do professionally is mainly to earn our living, and the gaming industry is not an exception. However, this industry is targeting entertainment, fun, and interactivity between a device and the user. Developers make money based on this. All the third-party integration and services help developers monetize the game, which directly or indirectly helps increase revenue.
Services can be any background support that is not game specific and can improve the experience of a game. Mostly, services use the Internet and device hardware and software programs. Mostly, a server-based service works with the application to provide the service.
We will have a detailed look at these aspects in this chapter through the following topics:
Google is currently the largest platform for Android applications. Moreover, Google is the owner of the Android OS. So, there can be no one better than Google to be the service provider for the Android platform.
Google Play Services is a background service for all Android devices to access all Google service product APIs. It was launched in 2012 to support Android development and take it to the next level.
The most used services in the Google Play Services package are:
Google Analytics is a service to track each and every event in the game. This can reveal user behavior, user actions, the number of users playing per day, each user's playing time, and so on. So, no data can go unnoticed by the developer. This analytic data helps developers identify the critical sections in the game. With this help, the developer can improve the game for better experience.
It is not always possible to track down each and every issue in the game in the testing or play testing phase. When the game gets bigger, with a huge user base, then it is more likely that unknown issues will be exposed. Google Analytics helps in these fields, not only with the current behavior of the user, but with the game performance as well.
Google Analytics is mostly used to track game events. So, the tracking events must be decided very carefully. The triggering points must also be placed in a strategic way. The developer might not require all the events and behavior data. More tracking may be even harmful to the application, as there would be more data use and more processing in the game.
The developer should always prioritize events. Events should be tracked based on the game flow design. They should then be validated by user action.
From the monetization point of view, it should always be a priority to track when the user is hitting the pay wall or which section is being visited more. A simple advertisement in the most visited section may increase the application's revenue.
In the modern world of gaming, there are many methods to monetize the application. In-app billing is one of the most popular methods. Google Play Services comes with the Google In-App Billing tool. This tool is directly associated with Google Play Store.
Through this tool, the developer can design some purchasable contents inside the game. For users, it is very easy to purchase from the built-in store of the Android application.
Let's have a quick look at the three purchasable options in Google IAB. We will have a detailed look at them later in this chapter:
Users can purchase this item multiple times from the store. Google does not keep track of these kinds of items. The most common example of this type of item is in-game virtual currency. Many games are designed around virtual currency, and most of the time, this factor is the backbone of game monetization.
They are basically one-time purchases for the user. Google always keeps track of these purchases made by a user for any application through Google IAB. Even when a user uninstalls the application and reinstalls it, it is possible to restore the non-consumable purchases to the user's account.
The most common item under this category is game modes. In many games, there are some open modes and some can be purchased. This system also works with the try-and-buy monetization aspect.
Google Play Services comes with IAB APIs. The developer needs to register the application on Google Play Store to get live access. This system works with item IDs, which are called SKUs. Each SKU represents an item in the Play Store. The developer may not use all the SKUs created in the Google Play account for a particular game.
We have already noted that Google IAB provides a platform to implement a direct digital purchasing system within the application. This saves great effort and time for both developers and consumers. Let's have a quick look at the advantages of Google IAB:
So far, Google IAB has proved to be an excellent system for both developers and consumers or users. However, there are several sectors where Google IAB is still lagging behind. Now, let's have look at the sectors where Google IAB needs to improve:
Despite these issues, Google IAB is still the most popular platform for billing for Android developers. Google has started including carrier billing services within Google IAB, which may prove to be the most significant feature.
Leaderboard is a platform for games and similar competitive applications where each and every user can track their progress among other users. Leaderboard has proved to be the driving force of many games. Google Play Services comes with an in-built Leaderboard system for Android applications.
Having a leaderboard integrated in games is always a plus, as it helps users compete with each other even when the game is not multiplayer. It is human psychology to try to become superior to others. Using this feature, there can be more user engagement than usual. However, the competing criteria on the leaderboard must be chosen carefully.
A good example of a leaderboard-driven game is Candy Crush. Users are very active, playing the simple game to stay ahead of their friends on the leaderboard.
There is no separate Google Leaderboard package. This can be included by integrating Google Play Services itself. However, Leaderboard has to be set up in the Google games account to use it.
The developer can choose any parameter or calculation to store leaderboard data. Google Leaderboard supports data from multiple leaderboards for a single game. Most of the developers use this feature efficiently to show different leader lists, depending on the time period, region, or some other customized parameter.
Primary variations of Google Leaderboard are of two types:
Leaderboard storage can be classified into two types, based on ascending and descending order. In terms of Google Leaderboard, they are called:
A score is always a numeric value, which is again classified into three formats:
In the case of a numeric value, the developer can specify the decimal placement. In the case of the time format, the developer needs to pass the score in milliseconds, and it will be automatically interpreted in the hh:mm:ss format. In the case of the currency format, the developer needs to specify the currency and its unit value beforehand. The Leaderboard will only take values in a unit and convert it to the specified unit format.
Leaderboard can have unique icons to display or indicate a unique leaderboard.
The push notification service can be achieved through the Google Cloud Messaging (GCM) service. Let's have a quick look at the cloud messaging architecture.
There are primarily four components used to implement push notifications for Android using GCM:
The database stores the registration details of a client or target device with the GCM service. So, each device is required to register only once. The same details are used to send push notifications to the registered target devices.
A target or client device is the platform where the message is pushed from the GCM. Each target device has a unique registration ID through the GCM. Without registration, a target device cannot receive any notifications.
The GCM service is responsible for registering devices and pushing messages to them. The server requests the GCM service with a list of registration IDs and customized messages. GCM is only responsible for pushing the given content to specified devices:
Now, let's discuss the push notification workflow. In the preceding diagram, the push notification system works according to the indicated indexes (for example, a, b, c, and so on):
Integrating push notifications is done in three steps:
The developer needs to set up a GCM client for the application, which is the medium of GCM communication. Here is a brief about client-side development for GCM communication services.
It requires a set of manifest permissions:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
The manifest will also require declaration of the GCM receiver and GCM service:
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRAION" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.gcm" /> </intent-filter> </receiver> <service android:name=".GcmService" android:exported="false"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service>
Let's have a look at the registration process for an application with GCM. Registration can be done in many ways, depending on the development style. We will follow the simplest processes within the main Android activity and store the registration ID for one-time registration of the application.
Here are the required declarations:
private final Context testContext = this; private final String SENDER_ID = "<Application ID from Google developer console>"; private final String SHARED_PREF = "com.test.gcmclient_preferences"; private final String GCM_TOKEN = "testgcmtoken";
The registration code should be put inside onCreate()
:
SharedPreferences appPrefs = testContext.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE); String token = appPrefs.getString(GCM_TOKEN, ""); if (token.isEmpty()) { try { InstanceID instanceID = InstanceID.getInstance(testContext); token = instanceID.getToken(SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); if (token != null && !token.isEmpty()) { SharedPreferences.Editor prefsEditor = appPrefs.edit(); prefsEditor.putString(GCM_TOKEN, token); prefsEditor.apply(); } } catch (Exception e) { e.printStackTrace(); } }
Now, let's define GCMService.java
to handle the GCM message:
public class GcmService extends GcmListenerService { @Override public void onMessageReceived(String from, Bundle data) { JSONObject jsonObject = new JSONObject(); Set<String> keys = data.keySet(); for (String key : keys) { try { jsonObject.put(key, data.get(key)); } catch (JSONException e) { e.printStackTrace(); } } try { sendNotification("Received: " + jsonObject.toString(5)); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onDeletedMessages() { Log.d("Message is deleted …"); } @Override public void onMessageSent(String msgId) { Log.d("Message is sent …" + msgId); } @Override public void onSendError(String msgId, String error) { Log.d("Sending Error … Msg" + msgId); Log.d("Error …" + error); } private void sendNotification(final String msg) { Log.d("Sending Msg …" + msg); } }
Google Play Services comes with a GCM system. GCM has to be enabled from the Google API console. Each registered application has its own unique application ID, which is required to configure the push notification system.
Here are the steps to enable GCM for the Android project:
Notification server development can be implemented by any cloud connection server technology. The developer needs to set up the application server by satisfying the following criteria:
Push notifications are an inevitable part of modern day game development. Push notifications are used for the following reasons:
Push notifications provide users with current updates and information on the game. There are many cases where the user downloads a game and then forgets about it. Sometimes, users leave games in between. Push notifications help these users regain interest in the game. This procedure improves user retention.
Through device settings and the notifications center, the developer can control the content that the user will see, and the user can be navigated accordingly.
Using user controls, the developer can track user behavior upon notifications. Depending on the user actions, the developer gets to know what the user likes and dislikes.
There are several ways to communicate with end users. Mostly, users do not often communicate with the developer. So, a one-way communication channel proves to be fruitful. A push notification system fits the role perfectly. It is the best possible medium to deliver messages about the latest news, updates of the game, offers, and features. In some design models, it can be used to deliver game status information to users.
3.21.46.92