Android App

No part of this help can be reproduced, transmitted, copied, stored in a retrieval system without prior written permission from Emoji Games, nor can it be translated into any language using any form or means, electronic, mechanical, photocopying, recording, or otherwise.

All copyrights, confidential information, patents, design rights, and all other intellectual property rights contained herein are the sole and exclusive property of Emoji Games. The information provided herein is considered accurate and reliable.

Emoji Games is also not responsible for the use of the game or any third-party patent or other rights infringement resulting from it.

1. Introduction

1.1. Purpose

The purpose of this document is for developers who want to integrate games provided by Emoji Games into Android games/apps.

1.2. Preparation

  • Development tools on PC: Eclipse, Android SDK.

  • Operating system of mobile devices: Android 2.3 or higher.

  • event_info.dat file created in BMG Event Creator tool (provided by Emoji Games).

You need to upload the event_info.dat file to the server and obtain the direct URL of the file.

1.3. Overview

2. Configuration

2.1. Import event_info.dat file

For inquiries about the event_info.dat file, please contact support@brandedminigames.com.

2.2. Upload event_info.dat file to the server

After receiving the event_info.dat file, you need to upload it to the server and obtain the direct URL.

Example: http://brandedminigames.com/BMGSDK_Demo/event_info.dat

2.3. Update AndroidManifest.xml file

2.3.1. Add permissions

Access permissions are required to check information about internet connection and network status. Add this permission to the file.

Insert the following code into the "AndroidManifest.xml" of the project.

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

2.3.2. Update Activity Intent-filter

Add a new intent filter as below in the main activity of the application.

<activity

    android:launchMode=”singleTask”>

    <intent-filter>
        <action android:name=”com.mbizglobal.bmg.PLAY” />
        <category android:name=”android.intent.category.DEFAULT” />
        <category android:name=”android.intent.category.BROWSABLE” />
        <data android:scheme=”The Package Name of your application”/>
</intent-filter>
</activity>

Don't forget the "singleTask" launchMode attribute. It will deliver the result to the correct activity.

Set the Scheme to the package name of the application.

The Scheme must be the same as the one registered on the campaign page of the Studio site.

2.3.3. Hardware acceleration

The performance of the Webview may be degraded when playing branded mini-game titles. To resolve this issue, you need to add one or more configurations to the app manifest.

<uses-feature android:glEsVersion=”0x00020000″ />
<application …
            android:hardwareAccelerated=”true” />

3. Implementation

3.1. Download and decode event_info.dat file from the server

3.1.1. Download event data file

First, you need to have the URL of the dat file containing the branded mini-game event.

Example: http://brandedminigames.com/BMGSDK_Demo/event_info.dat

To use the game demo event for testing, set the URL to the URL above. This is the event information data file for the game demo event. Alternatively, you can download this event_info.dat file and upload it to your server. The URL will be your server URL.

In your main Activity, use this code in the onCreate(Bundle savedInstanceState) method to download the dat file data and store it in a byte array. You can improve performance using a Handler or AsyncTask.

URL url = new
            URL(“http://brandedminigames.com/BMGSDK_Demo/event_info.dat”);
InputStream in = url.openStream();
byte[] inputBytes = IOUtils.toByteArray(in);

3.1.2. Data decoding

When you receive the byte array from the data file on the server, it is not usable because it is encoded.

  • The algorithm is "AES-128".

  • The key is "brandedminigames".

Use this code to decode the data.

String ALGORITHM = “AES”;
String TRANSFORMATION = “AES”;
String KEY = “brandedminigames”;
Key secretKey = new SecretKeySpec(KEY.getBytes(), ALGORITHM);
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(cipherMode, secretKey);
byte[] outputBytes = cipher.doFinal(inputBytes);
String outputString = new String(outputBytes, “UTF-8”);

Now that you have the outputString and it is a pure JSON string, parse this string into a JSONArray, JSONObject.

try {
    JSONArray jsonArr = new JSONArray(outputString);
    for (int i = 0; i < jsonArr.length(); i++) {
     JSONObject jobj = jsonArr.getJSONObject(i);
      
     // Checking event period
     String start = jobj.optString(“start”);
     String end = jobj.optString(“end”);        
     Date startDay = sdf.parse(start);          
     Date endDay = sdf.parse(end);
      
     // End of day
     Calendar c = Calendar.getInstance();
     c.setTime(endDay);
     c.set(Calendar.HOUR_OF_DAY, 23);
     c.set(Calendar.MINUTE, 59);
     c.set(Calendar.SECOND, 59);        
     endDay = c.getTime();
   
     if (endDay.compareTo(startDay) < 0) {
         continue;
     }
     Date today = new Date();
     if (today.compareTo(startDay) < 0) {
         continue;
     }
     if (today.compareTo(endDay) > 0) {
         continue;
     }
     // Checking event status
     if (jobj.optInt(“status”) != 1)
         continue;
     int mScore = 0;
     try {
         mScore = Integer.parseInt(jobj.optString(“maxScore”));
     } catch (Exception e) {
     }  
       /*
       * Now, save all fields above to your data struct (such as ArrayList)
 /*
       *jobj.optString(“campaignId”),
     *jobj.optString(“start”),
     *jobj.optString(“end”),
     *jobj.optInt(“status”),
     *jobj.optString(“url”),
     *jobj.optString(“title”),
     *jobj.optString(“desc”),
     *jobj.optInt(“maxScore”)
 
 
       */
    }
} catch (ParseException e) {
    //Exception is thrown when event_info.dat error
    //You handle exception by yourself
} catch (Exception e) {
    //You handle exception by yourself
}

Since you can create many events using the BMG Event Data Tool, the event information decoded from binary data to JSON data is an array list. You can select and use a specific event from the array list. In particular, it is a JSON array containing one or more JSON objects. If there are many events, you can store them using an ArrayList.

JSON object information:

Field nameDescription

start

Event start time. Format ‘MM/dd/yyyy’

end

Event end time. Format ‘MM/dd/yyyy’

status

Event status.0: Disable1: Enable

url

Event game url

title

Event title

desc

Event description

maxScore

Maximum possible score from this event game

campaignId

ID of current campaign

3.2. Store event information in memory

When you receive the event data, it is a good idea to store it in memory for later use. Using a Java global list eliminates the need to retrieve event information from the server again.

3.3. Build URL from the original URL in memory

After retrieving and decoding data from the event_info.dat file, you need to build a URL based on the URL received in the previous step to play the branded mini-game.

(String url = jobj.optString(“url”)).

The new URL is as follows:

String query = “?”;
if (url.contains(“?”))
   query = “&”;
uri = Uri.parse(url +
            query +
            “app_user=” + userId +
            “&route=” +
                   mainContext.getApplicationContext().getPackageName());

"app_user": This is a string format. It should be the email address or ID of the user obtained from the application after the user logs in. This information is used to identify each user who participated in the event mini-game and can become a winner through this parameter. It is detected at the end of the event. If the user is not logged in or does not have an account, you need to generate a random value. This parameter is required. Example: random value:

String userId = “Guest_” + UUID.randomUUID().toString().substring(0, 8);

3.4. Play the game

3.4.1. Play the game in an external browser

You can use the following code to call the browser to play the branded mini-game with the URI above.

Intent browserIntent = new Intent(Intent.ACTION_VIEW);
PackageManager packageManager = mainContext.getPackageManager();
browserIntent.setDataAndType(uri, “text/html”);
List<ResolveInfo> list =
                 packageManager.queryIntentActivities(browserIntent, 0);
 
 
//Call native android browser
for (ResolveInfo resolveInfo : list) {
    String activityName = resolveInfo.activityInfo.name;
     
    if (activityName.toLowerCase().contains(“com.android.browser”) ||
         activityName.toLowerCase().contains(“com.google.android.browser”) ||
         activityName.toLowerCase().contains(“com.sec.android.app.sbrowser”) ||
         activityName.toLowerCase().contains(“com.htc.sense.browser”)) {
        browserIntent =
                packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
        ComponentName comp =
                new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
        browserIntent.setAction(Intent.ACTION_VIEW);
        browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
        browserIntent.setComponent(comp);
        browserIntent.setData(uri);
        mainContext.startActivity(browserIntent);               
        return;
    }
}
 
 
//or call external browser (Chrome)
for (ResolveInfo resolveInfo : list) {
    String activityName = resolveInfo.activityInfo.name;
    if (activityName.toLowerCase().contains(“com.google.android.apps.chrome”)) {
        browserIntent =
                packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
        ComponentName comp =
                new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
        browserIntent.setAction(Intent.ACTION_VIEW);
        browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
        browserIntent.setComponent(comp);
        browserIntent.setData(uri);
        mainContext.startActivity(browserIntent);               
        return;
    }
}

When the game is finished, it will go to the Leaderboard. You can return to the app by clicking the complete button, as the href of the complete button on that page is an Android schema.

3.4.2. Play the game in WebView

If you don't want to use an external browser, you can define a unique activity containing only WebView to play the branded mini-game.

Of course, you still need to build the URL to play, similar to "3.3 Build URL from the original URL in memory."

You can implement the BMGWebView activity in the code as follows:

public class BMGWebView extends Activity {
    private WebView webView;
    @SuppressLint(“SetJavaScriptEnabled”) @Override
    protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     requestWindowFeature(Window.FEATURE_NO_TITLE);
     String url = getIntent().getStringExtra(“url”);
     if (url == null || url.equals(“”))
         finish();
     LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
     webView = new WebView(this);
     WebSettings s = webView.getSettings();
     s.setJavaScriptEnabled(true);
     s.setSupportMultipleWindows(false);
     s.setJavaScriptCanOpenWindowsAutomatically(false);
     s.setDomStorageEnabled(true);
     s.setDatabaseEnabled(true);
     s.setLightTouchEnabled(true);
     s.setLoadWithOverviewMode(false);
     s.setUseWideViewPort(true);
     s.setPluginState(WebSettings.PluginState.ON);
     s.setBuiltInZoomControls(false);
     s.setSupportZoom(false);
     s.setAllowFileAccess(true);
     s.setAppCachePath(this.getCacheDir().getAbsolutePath());
     s.setCacheMode(WebSettings.LOAD_DEFAULT);
     addContentView(webView, params);
     webView.setWebChromeClient(new WebChromeClient(){  
     });
      
     webView.setWebViewClient(new WebViewClient(){
         @Override
         public boolean shouldOverrideUrlLoading(WebView view,
                                                     String url) {
             if (url.startsWith(“intent:#Intent;”)){
                 url = url.replace(“intent:#Intent;”, “”);
                 String[] tokens = url.split(“;”);
                HashMap<String, String> map = new HashMap<String,
                                                               String>();
                for(int i=0;i<tokens.length;i++)
                {
                    String[] strings = tokens[i].split(“=”);
                    if(strings.length==2)
                    map.put(strings[0],
                              strings[1].replaceAll(“%2C”, “,”));
                }
                //get data
                String action = map.get(“action”);
                int scoreInt = 0;
                int rankInt = 0;
                try {
                     scoreInt =
                                  Integer.parseInt(map.get(“i.score”));
                     rankInt =
                                  Integer.parseInt(map.get(“i.rank”));
                } catch (Exception e) {
                }
                        //Now you have scoreInt, rankInt
                    //You can handle your code here
             }
             return super.shouldOverrideUrlLoading(view, url);
         }
     });
     webView.loadUrl(url);
    }
}

Now, after building the URL, use the following code to call the BMGWebView.

Intent webIntent = new Intent(mainContext, BMGWebView.class);
webIntent.putExtra(“url”, uri.toString());
mainContext.startActivity(webIntent);

3.5. Get game results

Using WebView, you can get game results in the WebViewClient implementation within BMGWebView.

If you are using an external browser, you need to implement a new method in the main activity.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (intent.getAction().equal(“com.mbizglobal.bmg.PLAY”)) {
         //get rank: intent.getIntExtra(“rank”, 0);
       //get score: intent.getIntExtra(“score”, 0);
    }
}

Result data:

Field nameDescription

rank

Latest ranking number on the leaderboard

score

Latest game score

3.6. Display game results with your own UI

In the previous step, you obtained the "ranking" and "score" values. You can define your own GUI, such as dialogues, pages, etc., to render game results and reward the main game.

3.7 How to provide rewards to application users based on event game scores

If your application or service uses its own point system (e.g., scores, mileage, or virtual currency), you can convert the user's score to the application's own point system. There are two ways to convert event game scores.

Method 1)

  • Using maxScore in Section 3.1.2 Decode data, you can get the maximum score that can be obtained in the current event game. To convert the event game score to your point system, you need the maximum score. Please refer to the table below.

A B(A / B = C)D (C * D)

Maximum reward points allowed in the application

Maximum score of a specific event game

Constant to be converted

User scoring event game

Reward points converted in the application

100

4,000

0.025

3,600

90

450

1,500

0.3

350

105

10,000

2,000

5

1,350

6,750

Method 2)

  • The score range of a specific event game can be adjusted by the Emoji Games service operation team. If you want to adjust the score range of a specific event game for direct use in the reward point system, please contact the Emoji Games service operation team at support@brandedminigames.com.

Last updated