<commit_before>= Android

== Dependencies

include:android::partial$dependencies.adoc[]

[NOTE]
====
If you use the https://github.com/googlesamples/unity-jar-resolver[Play Services Resolver plugin for Unity],
all dependencies should be taken care of automatically.

*Please use Play Services Resolver version >= 1.2.95.* Issues have been reported using version 1.2.72, and issues with other versions may also exist.
====

== Initialize Teak

There are a few ways to initialize Teak in an Android project, they are listed
from easiest to more complicated.

=== Option 1: Tell Teak to Auto-Initialize
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.

.Add this to the main activity in your AndroidManifest.xml
[source,xml]
----
<meta-data android:name="io.teak.sdk.initialize" android:value="true"/>
----
NOTE: This should work just fine for most games. You can go right to <<Configure Credentials>>

=== Option 2: Make Teak your Unity Main Activity
If you can't use auto-initialization, for some reason, edit your `Assets/Plugins/Android/AndroidManifest.xml`
and change your main `<activity>`

.From This
[source,xml]
----
<activity android:name="com.unity3d.player.UnityPlayerActivity"
          android:label="@string/app_name">
----

.To This
[source,xml]
----
<activity android:name="io.teak.sdk.wrapper.unity.TeakUnityPlayerActivity"
          android:label="@string/app_name">
----

You can now <<Configure Credentials>>

==== What About Shortcuts?
To preserve app shortcuts, add the following below (not inside) the `<activity>` you just changed:

[source,xml]
----
<activity-alias
    android:name="com.unity3d.player.UnityPlayerActivity"
    android:targetActivity="io.teak.sdk.wrapper.unity.TeakUnityPlayerActivity" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity-alias>
----

This creates an 'activity alias' which tells Android, "Our main activity used to
be com.unity3d.player.UnityPlayerActivity, but now it's
io.teak.sdk.wrapper.unity.TeakUnityPlayerActivity"

=== Option 3: Subclass TeakUnityPlayerActivity
If you can't change your main activity, and instead have your own custom activity
that subclasses `UnityPlayerActivity` then simply change:

.This
[source, java]
----
extends UnityPlayerActivity
----

.To
[source, java]
----
extends TeakUnityPlayerActivity
----

You can now <<Configure Credentials>>

=== Option 4: Add Teak to your Main Activity

If you can't subclass `TeakUnityPlayerActivity`, then you need to add the Teak
initialization calls into your custom activity.

==== Import Teak into your main activity

.Import the Teak Classes
[source, java]
----
import io.teak.sdk.Teak;
import io.teak.sdk.wrapper.unity;
----

==== Initialize Teak
Call ``<<Teak.onCreate(Activity)>>`` **before** the call to ``super.onCreate``, then call
``TeakUnity.initialize()`` **after** the call to ``super.onCreate``

.Call Teak.onCreate()
[source, java]
----
protected void onCreate(Bundle savedInstanceState) {
    Teak.onCreate(this);
    super.onCreate(savedInstanceState);
    TeakUnity.initialize();
    // ... etc
}
----

.Call setIntent()
[source, java]
----
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent); // << Add this line
}
----
NOTE: You only need to call setIntent() if your custom activity does not inherit
from `UnityPlayerActivity`, otherwise it is done by `UnityPlayerActivity`.

You can now <<Configure Credentials>>

=== 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": {
        "unity":"<unity-sdk-version>",
        "android":"<android-sdk-version>"
      },
      "run_id":"<some-guid>"
    }

And many other Teak log entries.

NOTE: If You Don't See Teak debug log messages, check to make sure your game is
being built in debug mode.

=== If You See

    java.lang.RuntimeException: Failed to find R.string.io_teak_api_key

It means that the `res/values/teak.xml` file was not found. See below...

== Configure Credentials

The Teak credentials are located in `Assets/Plugins/Android/res/values/teak.xml`

IMPORTANT: The Teak Editor scripts for Unity will manage this file for you. If
you are using the Teak Editor scripts, skip this step.

If your build environment requires that you create this file yourself, then the
file should look like this:

.res/values/teak.xml
[source,xml]
----
<?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`, and `YOUR_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.

=== What This Does
This provides Teak with the credentials needed to send information to the Teak Service.

== Set Notification Icons for your Game
To specify the icon displayed in the system tray, and at the top of the notification,
describe these resources in a file called `teak_icons.xml`.

NOTE: You will need two versions of this file. One located in `values` and the other
located in `values-v21`.

.teak_icons.xml
[source,xml]
----
<?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 `teak_icons.xml` file in `values` should point to a full-color icon, for devices
running less than Android 5, and the `teak_icons.xml` file in `values-v21` should point
to a white and transparent PNG for Android 5 and above.

IMPORTANT: To make sure that your white and transparent PNG shows up properly, use :doc:`Android Asset Studio's Notification icon generator <android/notification-icon>`.

NOTE: You may name the ``teak_icons.xml`` file anything you want, or include the values in an existing file, should you wish to do so.

== Setting Up Deep Linking

IMPORTANT: The Teak Editor scripts for Unity will manage this file for you. If
you are using the Teak Editor scripts, skip this step.

Add the following to the `<activity>` section of your `Assets/Plugins/Android/AndroidManifest.xml`:

.AndroidManifest.xml
[source,xml]
----
    <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_SUBDOMAIN.jckpt.me" />
        <data android:scheme="https" android:host="YOUR_SUBDOMAIN.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>
----

NOTE: Replace `YOUR_TEAK_APP_ID` with your Teak App Id and `YOUR_SUBDOMAIN` with your Teak Subdomain.

Your Teak App Id and Teak Subdomain can be found in the Settings for your app on the Teak dashboard.

=== What This Does
This tells Android to look for deep link URLs created by Teak.
<commit_msg>Fix include in docs<commit_after>= Android

== Dependencies

include::android::partial$dependencies.adoc[]

[NOTE]
====
If you use the https://github.com/googlesamples/unity-jar-resolver[Play Services Resolver plugin for Unity],
all dependencies should be taken care of automatically.

*Please use Play Services Resolver version >= 1.2.95.* Issues have been reported using version 1.2.72, and issues with other versions may also exist.
====

== Initialize Teak

There are a few ways to initialize Teak in an Android project, they are listed
from easiest to more complicated.

=== Option 1: Tell Teak to Auto-Initialize
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.

.Add this to the main activity in your AndroidManifest.xml
[source,xml]
----
<meta-data android:name="io.teak.sdk.initialize" android:value="true"/>
----
NOTE: This should work just fine for most games. You can go right to <<Configure Credentials>>

=== Option 2: Make Teak your Unity Main Activity
If you can't use auto-initialization, for some reason, edit your `Assets/Plugins/Android/AndroidManifest.xml`
and change your main `<activity>`

.From This
[source,xml]
----
<activity android:name="com.unity3d.player.UnityPlayerActivity"
          android:label="@string/app_name">
----

.To This
[source,xml]
----
<activity android:name="io.teak.sdk.wrapper.unity.TeakUnityPlayerActivity"
          android:label="@string/app_name">
----

You can now <<Configure Credentials>>

==== What About Shortcuts?
To preserve app shortcuts, add the following below (not inside) the `<activity>` you just changed:

[source,xml]
----
<activity-alias
    android:name="com.unity3d.player.UnityPlayerActivity"
    android:targetActivity="io.teak.sdk.wrapper.unity.TeakUnityPlayerActivity" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity-alias>
----

This creates an 'activity alias' which tells Android, "Our main activity used to
be com.unity3d.player.UnityPlayerActivity, but now it's
io.teak.sdk.wrapper.unity.TeakUnityPlayerActivity"

=== Option 3: Subclass TeakUnityPlayerActivity
If you can't change your main activity, and instead have your own custom activity
that subclasses `UnityPlayerActivity` then simply change:

.This
[source, java]
----
extends UnityPlayerActivity
----

.To
[source, java]
----
extends TeakUnityPlayerActivity
----

You can now <<Configure Credentials>>

=== Option 4: Add Teak to your Main Activity

If you can't subclass `TeakUnityPlayerActivity`, then you need to add the Teak
initialization calls into your custom activity.

==== Import Teak into your main activity

.Import the Teak Classes
[source, java]
----
import io.teak.sdk.Teak;
import io.teak.sdk.wrapper.unity;
----

==== Initialize Teak
Call ``<<Teak.onCreate(Activity)>>`` **before** the call to ``super.onCreate``, then call
``TeakUnity.initialize()`` **after** the call to ``super.onCreate``

.Call Teak.onCreate()
[source, java]
----
protected void onCreate(Bundle savedInstanceState) {
    Teak.onCreate(this);
    super.onCreate(savedInstanceState);
    TeakUnity.initialize();
    // ... etc
}
----

.Call setIntent()
[source, java]
----
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent); // << Add this line
}
----
NOTE: You only need to call setIntent() if your custom activity does not inherit
from `UnityPlayerActivity`, otherwise it is done by `UnityPlayerActivity`.

You can now <<Configure Credentials>>

=== 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": {
        "unity":"<unity-sdk-version>",
        "android":"<android-sdk-version>"
      },
      "run_id":"<some-guid>"
    }

And many other Teak log entries.

NOTE: If You Don't See Teak debug log messages, check to make sure your game is
being built in debug mode.

=== If You See

    java.lang.RuntimeException: Failed to find R.string.io_teak_api_key

It means that the `res/values/teak.xml` file was not found. See below...

== Configure Credentials

The Teak credentials are located in `Assets/Plugins/Android/res/values/teak.xml`

IMPORTANT: The Teak Editor scripts for Unity will manage this file for you. If
you are using the Teak Editor scripts, skip this step.

If your build environment requires that you create this file yourself, then the
file should look like this:

.res/values/teak.xml
[source,xml]
----
<?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`, and `YOUR_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.

=== What This Does
This provides Teak with the credentials needed to send information to the Teak Service.

== Set Notification Icons for your Game
To specify the icon displayed in the system tray, and at the top of the notification,
describe these resources in a file called `teak_icons.xml`.

NOTE: You will need two versions of this file. One located in `values` and the other
located in `values-v21`.

.teak_icons.xml
[source,xml]
----
<?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 `teak_icons.xml` file in `values` should point to a full-color icon, for devices
running less than Android 5, and the `teak_icons.xml` file in `values-v21` should point
to a white and transparent PNG for Android 5 and above.

IMPORTANT: To make sure that your white and transparent PNG shows up properly, use :doc:`Android Asset Studio's Notification icon generator <android/notification-icon>`.

NOTE: You may name the ``teak_icons.xml`` file anything you want, or include the values in an existing file, should you wish to do so.

== Setting Up Deep Linking

IMPORTANT: The Teak Editor scripts for Unity will manage this file for you. If
you are using the Teak Editor scripts, skip this step.

Add the following to the `<activity>` section of your `Assets/Plugins/Android/AndroidManifest.xml`:

.AndroidManifest.xml
[source,xml]
----
    <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_SUBDOMAIN.jckpt.me" />
        <data android:scheme="https" android:host="YOUR_SUBDOMAIN.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>
----

NOTE: Replace `YOUR_TEAK_APP_ID` with your Teak App Id and `YOUR_SUBDOMAIN` with your Teak Subdomain.

Your Teak App Id and Teak Subdomain can be found in the Settings for your app on the Teak dashboard.

=== What This Does
This tells Android to look for deep link URLs created by Teak.

{'fraction_non_alphanumeric': 0.11308532296872108, 'fraction_numerical': 0.004195200197421186, 'mean_word_length': 4.071964956195244, 'pattern_counts': {'":': 22, '<': 119, '<?xml version=': 4, '>': 117, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 42}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4423234', 'n_tokens_mistral': 4927, 'n_tokens_neox': 4731, 'n_words': 1715}