Game of Whales Android SDK
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
AndroidExample
SamsungExample
LICENSE
README.md

README.md

Game of whales Android Native SDK

Changelog

2.0.20 (Nov 20, 2018)

ADDED

  • The supporting of cross promotion ads was added.

2.0.19 (Oct 29, 2018)

FIXED

  • Sometimes events (for example, pushDelivered) were not sent to GOW server. The issue was fixed.

2.0.16 (Aug 06, 2018)

FIXED

  • Usage of Store parameter was fixed.

2.0.15 (Jun 14, 2018)

FIXED

  • Push notifications were not supported for Android 8 +.

2.0.14 (Jun 14, 2018)

ADDED

  • redeemable parameter was added to SpecialOffer class.

2.0.13.2 (May 15, 2018)

FIXED

  • Usage of Store parameter was fixed.

2.0.13.0 (May 15, 2018)

ADDED

  • Custom data is supported for special offers.

FIXED

  • Sometimes events from apps could not be sent to Game of Whales server.

2.0.12 (May 14, 2018)

ADDED

  • The new Google Play Billing is supported.
  • The information about a device's locale is sent to Game of Whales.

2.0.11 (Dec 20, 2017)

FIXED

  • pushDelivered event could be sent twice.

2.0.10 (Dec 20, 2017)

MODIFIED

  • Push notification about special offer comes at the same time with the special offer (new parameter offer was added): void onPushDelivered(SpecialOffer offer, String campID, String title, String message);

  • setPushNotificationsEnable method was added to allow user to turn off the push notifications.

2.0.9 (Nov 21, 2017)

MODIFIED

  • store parameter was added to initializing.

Implementation Guide

The SDK will ask the following permissions on the user's device:

    <uses-permission android:name=android.permission.ACCESS_NETWORK_STATE/>
    <uses-permission android:name=android.permission.INTERNET/>
    <uses-permission android:name=android.permission.WAKE_LOCK/>

Implement the SDK to your project.

Step 1

Add the following dependencies to build.gradle:

dependencies {
	...
       compile 'com.gameofwhales:sdk:2.0.20@aar'

Step 2

Add the following row to your AndroidManifest.xml and change GAME_ID to your game key. You can find your game key on Game Settings page of Game of Whales.

...
<meta-data android:name="gameOfWhales.gameId" android:value="GAME_ID" />
</application>

Step 3

Init Game of Whales SDK in your Activity Start class.

// GoW_import
import com.gameofwhales.sdk.GameOfWhales;
import com.gameofwhales.sdk.GameOfWhalesListener;
import com.gameofwhales.sdk.SpecialOffer;

...
@Override
    protected void onCreate(Bundle savedInstanceState) {
    ...
    // GameOfWhakes SDK initialization
    final String store = GameOfWhales.STORE_GOOGLEPLAY;
    //final String store = GameOfWhales.STORE_SAMSUNG;
    GameOfWhales.Init(this, store, gowListener);

Step 4

Create new listener and add your functionality to it.

For example:

private GameOfWhalesListener gowListener = new GameOfWhalesListener() {

        @Override
        public void onSpecialOfferAppeared(SpecialOffer specialOffer) {
            Log.i(TAG, "onSpecialOfferAppeared: " + specialOffer.toString());
        }

        @Override
        public void onSpecialOfferDisappeared(SpecialOffer specialOffer) {
            Log.i(TAG, "onSpecialOfferDisappeared: " + specialOffer.toString());
        }


        @Override
        public void onPushDelivered(SpecialOffer offer, String campID, String title, String message) 
        {
           //It's called to show notification in opened game.
        }

        @Override
        public void onPurchaseVerified(final String transactionID, final String state) {

            
            if (state.equals(GameOfWhales.VERIFY_STATE_ILLEGAL))
            {
	    	//TODO: Refund money if state is illegal
            }
        }
    };

The verify state can be:

  • VERIFY_STATE_LEGAL - a purchase is normal.
  • VERIFY_STATE_ILLEGAL - a purchase is a cheater's.
  • VERIFY_STATE_UNDEFINED - GOW server couldn't define the state of a purchase. 

Purchases

Check that Android Bundle Identifier and Android Public License Key have been filled on Game Settings page before you will make a purchase.

Step 5.1 (only if you use old Google Billing)

Add the following line to the code when you get in-app details:

Bundle details = null;
try {
    details = service.getSkuDetails(3, pck, "inapp", query);
} catch (RemoteException e)
{
    Log.e(TAG, "RemoteException while getting details");
}

int response = details.getInt("RESPONSE_CODE");
if (response == 0)
{
     	// GoW_call DetailsReceived()
        GameOfWhales.DetailsReceived(data);
}

And add the following line to onActivityResult for successful purchase:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
	if (requestCode == BILLING_REQUEST_CODE && resultCode == RESULT_OK) 
	{
	...
        	// GoW_call InAppPurchased()
        	GameOfWhales.InAppPurchased(data);

Step 5.2 (only if you use new version of Google Play Billing)

Add the following line to the code when you get in-app details:

 @Override
 public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
        for (SkuDetails d : skuDetailsList)
        {
              GameOfWhales.DetailsFromString(d.toString());

And add the following line to onPurchasesUpdated for successful purchase:

 @Override
 public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
	if (responseCode == BillingClient.BillingResponse.OK && purchases != null) {
            	for (Purchase purchase : purchases) {
			GameOfWhales.InAppPurchased(purchase.getOriginalJson(), purchase.getSignature());

Step 6 (only if you use Samsung purchases)

	String purchaseID = _purchaseVo.getPurchaseId();
        String paymentID = _purchaseVo.getPaymentId();
        String currency = _purchaseVo.getCurrencyCode();
        double price = _purchaseVo.getItemPrice().doubleValue();
        String sku = _purchaseVo.getItemId();
        String receipt = GameOfWhales.BuildSamsungReceipt(paymentID, purchaseID);

        GameOfWhales.InAppPurchased(sku, price, currency, paymentID, receipt);

You can find an example of using the SDK for Samsung here.

If you can use the previous methods for purchases, you can use inAppPurchased method with the following parameters:

	String receipt = BuildGooglePlayReceipt(originalJson, signature);
	inAppPurchased(sku, price, currency, transactionID, receipt.toString());

Special Offers

Step 7

Before any product can be used in a special offer it has to be bought by someone after SDK has been implemented into the game. Please make sure your game has at least one purchase of the product that is going to be used in the special offer. If you want to create a special offer for in game resource, please, make sure your game has at least one converting event with the appropriate resource.

In order to receive special offer call the following method:

	SpecialOffer so = GameOfWhales.GetSpecialOffer(itemID);
	if (so!= null)
	{...

Special offer can influence a product's price:

	if (so.hasPriceFactor())
	{
		cost *= so.priceFactor;
	}

Special offer can also influence count (count of coins, for example) which a player receive by purchase:

	if (so.hasCountFactor())
	{
	 	coins *= so.countFactor;
	}

It's possible to pass custom data to special offers. In order to get the data in game's side, use customValues parameter of SpecialOffer class.

       String str = specialOffer.customValues.get("your_str").toString();
       Integer number = Integer.valueOf(specialOffer.customValues.get("your_int").toString());
       Boolean bool = Boolean.valueOf(specialOffer.customValues.get("your_bool").toString());

Push notifications

Step 8

Add a receiver to send information about notifications to your manifest and specify your Android Bundle Identifier instead APP_BUNDLE.

     <receiver
        android:name="com.gameofwhales.sdk.util.GOWBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
               <action android:name="com.google.android.c2dm.intent.RECEIVE" />
               <category android:name="APP_BUNDLE"/>
            </intent-filter>
        </receiver>
     
     ...
     </application>

Step 9

Add the next permissions to your manifest and specify your Android Bundle Identifier instead APP_BUNDLE.

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="APP_BUNDLE.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="APP_BUNDLE.permission.C2D_MESSAGE" />

If you haven't had an android manifest in your project yet, you can use GOWAndroidManifest.xml from SDK, but you need renaming of it to AndroidManifest.xml and replace APP_BUNDLE to your Android Bundle Identifier wherever it is defined.

Step 10

Register your project in the Firebase console.

If you use Google Cloud Messaging:

Call the following method:

	GameOfWhales.SetAndroidProjectID(PROJECT_NUMBER);//or SenderID

Check that the following library have been added to your Android project in gradle file:

	compile 'com.google.android.gms:play-services-gcm:xxx'

If you use Firebase Cloud Messaging:

Add Firebase to your project.

Call the following method during the starting of your game when Firebase has already been initialized:

	GameOfWhales.UpdateToken(FirebaseInstanceId.getInstance().getToken(), GameOfWhales.PROVIDER_FCM);

Step 11 (only if push notifications are shown inside your app by using the game's code)

In order to send the information to Game of Whales regarding a player's reaction on a push notification (to increase push campaign's Reacted field) of an already started app call the following method:

      
      @Override
      public void onPushDelivered(SpecialOffer offer, String campID, String title, String message) 
      {
      		//Show the notification to a player and then call the following method
        	GameOfWhales.PushReacted(campID);
      }

Step 12

In order to enable or disable push notifications, use the following method:

	GameOfWhales.SetPushNotificationsEnable(false);

In order to check notifications implementation send a test notification.

Profiles

Step 13

You can send additional data about your players by using the Profile method. Profile method should be called if key parameters of your app or a player have changed.

In order to work with AI offers you should send at least 5 number-type properties and at least one progress based parameter.

If you send more than 3000 properties, Game of Whales will sort all properties alphabetically and will save only the first 3000.

If the length of a string-type property is more than 64 characters, Game of Whales will save only the first 64 characters.

For example:

	HashMap<String, Object> changes = new HashMap<>();
        changes.put("class", getUserClass());
        changes.put("gender", Boolean.valueOf(getGender()));
        changes.put("location", getLocation());
        changes.put("level", getLevel());
        GameOfWhales.Profile(changes);

Converting

Step 14

Converting method should be called when you buy or get some in-game objects, coins, currency, etc.

For example: Someone bought one bike_1 for 1000 coins and 50 gas. You should call the following method for this purchase:

	Map<String, Long> resources = new HashMap<>();
        resources.put("bike_1", 1);
	resources.put("gas", -50);
        resources.put("coins", -1000);
        GameOfWhales.Converting(resources, place);

You can also use the following methods:

Consume - to buy items for game currency. For example:

	GameOfWhales.Consume("coins", 1000, "gas", 50, "shop");

It means that someone spent 1000 "coins" for 50 "gas" in "shop".

Acquire - for in-app purchases. It's important to call acquire method after InAppPurchased. For example:

	GameOfWhales.Acquire("coins", 1000, sku, 1, "bank");

It means that someone has acquired 10000 "coins" for 1 "sku" in "bank".

Cross promotion ads

It's supported since version 2.0.20 of SDK for Android.

To handle the ads set in Game of Whales, you need to do some actions:

Step 15

Subscribe to the following events to get the information about the current state of the ads by using GameOfWhalesListener class:

private GameOfWhalesListener gowListener = new GameOfWhalesListener() {

        ...
	
        @Override
        public void onAdLoaded() {
            
        }

        @Override
        public void onAdLoadFailed() {
           
        }

        @Override
        public void onAdClosed() {
            
        }
	
	...
    };

Step 16

Start to load the ads at any place of your code (for example, during the launch of the game):

	GameOfWhales.LoadAd();    

Step 17

Add the following code to the part of your game where you want to show the ads:

    if (GameOfWhales.IsAdLoaded())
    {
	GameOfWhales.ShowAd();
    }
    else
    {
	GameOfWhales.LoadAd();
    }

You can find an example of using the SDK here.

Run your game. The information about it began to be collected and displayed on the dashboard. In a few days, you will get data for analyzing.

This article includes the documentation for Game of Whales Android Native SDK. You can find information about another SDK in documentation about Game of Whales.