Integration
The latest version of the Teak Android SDK is always available at:
Dependencies
-
org.greenrobot:eventbus:3.3.1
-
com.google.android.gms:play-services-ads-identifier:16+
-
com.google.android.gms:play-services-base:16+
-
com.google.android.gms:play-services-basement:16+
-
com.google.firebase:firebase-messaging:21+
-
androidx.core:core:1.0.+
-
androidx.work:work-runtime:2.5.+
-
com.android.installreferrer:installreferrer:2.2+
Auto-Initialize Teak
Teak can take advantage of Firebase’s initialization of ContentProviders to auto-initialize. This is the easiest way to integrate Teak with your Android target.
- All you need to do is add this to the main activity in your AndroidManifest.xml
<meta-data android:name="io.teak.sdk.initialize" android:value="true"/>
This should work just fine for most games. You can go right to Edit Teak XML |
Otherwise Add Teak to your Main Activity
If you don’t want to use auto-initialization then you need to add the Teak initialization calls into your custom activity.
Call Teak.onCreate
protected void onCreate(Bundle savedInstanceState) {
Teak.onCreate(this);
super.onCreate(savedInstanceState);
// ... etc
}
Always call Teak.onCreate(Activity) before the call to super.onCreate. |
Call setIntent()
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent); // << Add this line
}
What This Does
This lets Teak hook into the Android app lifecycle and configure itself, listen for Facebook logins, billing events, and begin sending information to the Teak Service.
Testing It
Run your game on an Android device, and look at the Android debug log output.
You Should See
{
"event_type":"teak.state",
"log_level":"INFO",
"timestamp":"<timestamp>",
"event_data": {
"state":"Created",
"old_state":"Allocated"
},
"event_id":1,
"sdk_version": {
"android":"<android-sdk-version>"
},
"run_id":"<some-guid>"
}
And many other Teak log entries.
If You Don’t See Teak debug log messages, check to make sure your game is being built in debug mode. |
Edit Teak XML
If your build environment needs to provide the file itself, this is what it should look like
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="io_teak_app_id">YOUR_TEAK_APP_ID</string>
<string name="io_teak_api_key">YOUR_TEAK_API_KEY</string>
</resources>
- NOTE
-
Replace
YOUR_TEAK_APP_ID
, andYOUR_TEAK_API_KEY
with your game’s values.
Your Teak App Id and API Key can be found in the Settings for your app on the Teak dashboard.
Set Notification Icons for your Game
To specify the icon displayed in the system tray, and at the top of the notification, specify these resources.
- You will need two versions of this file. One located in
values
and the other located invalues-v21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- The tint-color for your silouette icon, format is: 0xAARRGGBB -->
<integer name="io_teak_notification_accent_color">0xfff15a29</integer>
<!-- Icons should be white and transparent, and processed with Android Asset Studio -->
<drawable name="io_teak_small_notification_icon">@drawable/YOUR_ICON_FILE_NAME</drawable>
</resources>
The file in values
should point to a full-color icon, for devices running less than Android 5, and the file in values-v21
should point to a white and transparent PNG for Android 5 and above.
To make sure that your white and transparent PNG shows up properly, see Notification Icons. |
Setting Up Deep Linking
Add the following to the <activity>
section of your Android manifest:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="YOUR_SHORTLINK_DOMAIN.jckpt.me" />
<data android:scheme="https" android:host="YOUR_SHORTLINK_DOMAIN.jckpt.me" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="teakYOUR_TEAK_APP_ID" android:host="*" />
</intent-filter>
Replace YOUR_TEAK_APP_ID with your Teak App Id and YOUR_SHORTLINK_DOMAIN with your Teak ShortLink Domain.
|
Your Teak App Id and Teak Shortlink Domain can be found in the Settings for your app on the Teak dashboard.
Subscribing to Events
Teak uses EventBus to send events to your game.
Events
- Teak.NotificationEvent
-
A notification has been received.
- Teak.RewardClaimEvent
-
A reward claim has happened.
- Teak.LaunchFromLinkEvent
-
The app was launched from a URL created on the Teak dashboard.
- Teak.UserDataEvent
-
Data about the user has become available, or has been updated.
@Subscribe
public void onNotification(Teak.NotificationEvent event) {
if (event.isForeground) {
// A notification was received while the game was in the foreground
} else {
// The game was launched via this notification
}
}