LogoLogo
My AppsLive demoNewsArticles
  • Introduction
  • 📌Product updates: 2025
    • 2024
    • 2023
  • Getting Started
    • Registration
    • Adding a space
    • Adding an app to the space
  • Basic Events & Custom Events
  • Integration
    • Expert Tips
      • What to track
      • Payments & Anti-cheat
      • Check your integration
    • Integration of SDK 2.0+
      • SDK Integration
        • Android
        • iOS
        • macOS
        • Windows
        • Web
          • Web SDK Integration
          • Web SDK Releases
        • Unity
        • Unreal Engine
        • Godot Engine
      • Automatic payment tracking
        • App Store
        • Google Play
      • Setting up Events
        • Basic methods
        • Secondary methods
        • User profile
        • Anticheat methods
        • Track sessions
      • Push notifications
        • Android
        • iOS
        • Windows (UWP)
        • Unity
          • Android
          • iOS
          • Windows (UWP/WSA)
        • Unreal Engine
      • A/B testing
        • Description of A/B testing on the SDK side
        • Working with A/B tests in the devtodev interface
        • A/B testing examples
    • Integration of SDK 1.0+ (deprecated)
      • SDK Integration
        • iOS
        • Android
        • Windows 8.1 and 10
        • Web
        • Unity
        • Mac OS
        • Adobe Air
        • UE4
      • Setting up Events
        • Basic methods
        • Secondary methods
        • User profile
        • Anti-cheat Methods
      • Push Notifications
        • IOS
        • Android
        • Windows 8.1 and Windows 10
        • Unity
        • Abode Air
        • UE4
    • Test Devices
    • Server API
      • Data API 2.0
      • Subscription API
      • Push API
        • IOS
        • Android
        • Windows UWP
        • Windows
      • Raw Export
      • Labels API
      • Data API
    • Import historical data via API
    • Data Export
      • Data Export to Cloud Storage (BigQuery / Amazon S3)
  • 3rd Party Sources
    • Attribution Trackers
      • AppsFlyer
      • Adjust
      • Branch.io
      • Kochava
      • Tenjin
      • Tune (MAT)
      • Singular
      • Custom postback API
      • Facebook Ads referral decryption
    • App Marketplace Data
      • App Store Connect Stats
      • App Store Subscriptions
      • Google Play Console Stats
      • Google Play Subscriptions
      • AppGallery Connect Stats
    • Ad revenue
      • AdColony
      • AdMob
      • Facebook
      • MoPub
      • Unity Ads
      • Vungle
      • Ad revenue API
    • Cohort export
  • Reports and Functionality
    • Space-related Reports and Functionality
      • Overview
      • Custom dashboards & Reports
      • SQL
        • SQL tips
        • SQL Query examples
      • Audience overlap
    • Project-related Reports and Functionality
      • Overview
        • Real-Time Dashboard
        • Acquisition reports
        • Engagement reports
        • Monetization reports
        • In-game analysis reports
        • Cohort analysis
      • Reports
      • Push Notifications
        • Android Notifications
        • IOS Notifications
        • Windows Notifications
        • Button Templates
      • Predictions
      • Users & Segments
      • Filters
      • A/B Testing
      • Tuning
      • Settings
  • Metrics and Glossary
    • Ad networks metrics
    • Market Metrics
    • Prediction Metrics
    • SDK Metrics
    • Subscription metrics
  • Space Management
  • User Profile Management
  • Limits
  • Scenarios and Best Practices
    • Analytics use cases
    • Match-3
    • MMORPG Games
    • Hyper-Casual games
    • Social Casino
    • RPG games
    • Farming games
    • Non-gaming app
    • Acquisition Example
  • FAQ
    • Identification
    • Raw Data
    • All about data discrepancies
  • Slack
Powered by GitBook
On this page
  • Platform integration
  • Module initialization
  • Set a custom icon and sound for push notifications
  • External interface of the DTDMessaging module for Android platform
  • Class for receiving Notification data (DTDPushMessage). Main class properties
  • Class for handling buttons clicked in the notification (DTDActionButton)

Was this helpful?

Export as PDF
  1. Integration
  2. Integration of SDK 2.0+
  3. Push notifications
  4. Unity

Android

Android Integration

PreviousUnityNextiOS

Last updated 18 days ago

Was this helpful?

Platform integration

Push Notifications on Android are sent with the help of the FCM service.

How to create a project in Firebase and integrate Firebase Services into your application, you can find in .

Next, you need to specify the FCM Server key in the push notifications integration settings panel in the application settings section in devtodev service (App → Settings → Push notifications → Push notifications panel)

To get the FCM Server key, go to the Project Settings of your Android project in the Firebase Console and copy the Server key from the Cloud Messaging tab.

Download google-services.json and put it to Assets folder.

Module initialization

2. After the DTDAnalytics initialization block add:

DTDMessaging.Android.Initialize();

3. To activate the Messaging module, call :

DTDMessaging.Android.StartPushService();

Optional:

You can listen to basic notification module events. To do this, create a class that implements the IDTDPushListener interface and pass it to the DTDMessaging.Android.SetPushListener method.

Example of the class:

public class MyPushListener : IDTDPushListener
{
    public void OnPushServiceRegistrationSuccessful(string deviceId)
    {
        Debug.Log(deviceId);
    }

    public void OnPushServiceRegistrationFailed(string error)
    {
        Debug.Log(error);

    }

    public void OnPushNotificationReceived(DTDPushMessage message)
    {
        Debug.Log(message);
    }

    public void OnInvisibleNotificationReceived(DTDPushMessage message)
    {
        //IOS only.
    }

    public void OnPushNotificationOpened(DTDPushMessage pushMessage, DTDActionButton actionButton)
    {
        Debug.Log(pushMessage.ToString());
        Debug.Log(actionButton.ToString());
    }
}

Full example of notification module initialization:

public class MyPushListener : IDTDPushListener
{
    public void OnPushServiceRegistrationSuccessful(string deviceId)
    {
        Debug.Log(deviceId);
    }

    public void OnPushServiceRegistrationFailed(string error)
    {
        Debug.Log(error);
    }

    public void OnPushNotificationReceived(DTDPushMessage message)
    {
        Debug.Log(message);
    }

    public void OnInvisibleNotificationReceived(DTDPushMessage message)
    {
        Debug.Log(message);
    }

    public void OnPushNotificationOpened(DTDPushMessage pushMessage, DTDActionButton actionButton)
    {
        Debug.Log(pushMessage.ToString());
        Debug.Log(actionButton.ToString());
    }
}

public class NotificationExample : MonoBehaviour
{
    private const string APP_KEY = "***************"
    void Start()
    {
        DTDAnalytics.Initialize(APP_KEY);
        DTDMessaging.Android.SetPushListener(new PushListener());
        DTDMessaging.Android.Initialize();
        DTDMessaging.Android.StartPushService();
    }
}

Set a custom icon and sound for push notifications

Unity 2019 and older

To set a custom sound, icon and its colour in a push notification, copy icons and sounds files in the Assets/Plugins/Android/res/ folder and add the following strings to the manifest file code:

<meta-data
 android:name="com.devtodev.push.default_small_icon"
 android:resource="@drawable/ic_icon_name" />

<meta-data
 android:name="com.devtodev.push.default_small_icon_color"
 android:resource="@color/icon_color" />

To set a large user icon in the push notification, add:

<meta-data
android:name="com.devtodev.push.default_large_icon"
android:resource="@mipmap/ic_large_icon_name"/>

Unity 2020 and newer

  • Delete the \Assets\Plugins\Android\res folder (together with the .meta file) - it will cause an error during assembly.

  • Create a new folder in a separate folder outside of the project.

  • In the new folder, create AndroidManifest.xml with the following content (replace company and package with you own names)

<manifest package="com.company.package">
</manifest>
  • Create a res folder in the same folder.

  • Add your resources to the res folder while keeping the folder structure intact (drawable, xml, raw, etc.). An example of the resulting structure:

├─── AndroidManifest.xml
└─── res
    └─── drawable
        └─── smallIcon0.png
     └─── mipmap
        └─── largeIcon0.png
     └─── raw
        └─── iconsound.wav 
  • Run the following code in the in the command line/terminal:

jar cvf resources.aar -C . .
  • Place the resulting aar file to the \Assets\Plugins\Android\ (edited) folder

  • Add the following strings to the project’s Android manifest file ( \Assets\Plugins\Android\AndroidManifest.xml):

<meta-data android:name="com.devtodev.push.default_small_icon" android:resource="@drawable/smallIcon0" />
<meta-data android:name="com.devtodev.push.default_large_icon" android:resource="@mipmap/largeIcon0" />

External interface of the DTDMessaging module for Android platform

Method
Description

void DTDMessaging.Android.Initialize()

The push notification initialization method

void DTDMessaging.Android.StartPushService()

The push notification activation method. It passes the isAllowed current state

void DTDMessaging.Android.PushIsAllowed (bool isAllowed)

A property responsible for the activation/deactivation of push notifications.When the state transitions, it sends a pt with isAllowed (true or false) status to the server.

The isAllowed flag status is stored in the SDK.

void DTDMessaging.Android.GetPushState(Action<bool?> onGetPushState)

The method that returns the push module state to onGetPushState callback. If getting the current state is impossible, it returns null

void DTDMessaging.Android.GetToken(Action<string> onGetToken)

The method that returns push registration token to onGetToken callback

void DTDMessaging.Android.ProcessPushNotification (IDictionary<string, string> firebaseMessaging)

Used to pass the push notification to the FirebaseMessagingService if it was implemented by the client but not by the SDK

void DTDMessaging.SetPushListener (IDTDPushListener pushListener)

It sets a listener for push notification event trapping

Class for receiving Notification data (DTDPushMessage). Main class properties

Property
Description

IDictionary<string,string> GetData():

Complete information passed with the push notification.

DTDActionType ActionType:

The property that returns the value of enum’s DTDActionType.

Possible values:

App - app open

Url - external link open

Share - share content

Deeplink - an in-app link opening

string ActionString

The property that returns an optional action identifier

IDictionary<string,string> AdditionalData()

Additional data sent to push notification

Class for handling buttons clicked in the notification (DTDActionButton)

Property
Description

DTDActionType ActionType

The property that returns the value of enum’s DTDActionType.

Possible values:

App - app open

Url - external link open

Share - share content

Deeplink - an in-app link opening

string ActionString

Property that returns an optional action identifier

string ButtonId

Property that returns the ID of the clicked button

string ButtonText

Property that returns the text of the clicked button

string ButtonIcon

Property that returns the button icon name

bool IsBackground

The button-click app open mode

1. For the Messaging module to function you need the basic Analytics package. Before the notification initialization, you need to initialize the SDK. More about it you can read here: .

Unity Integration
Firebase documentation