Android
Android Integration
Last updated
Android Integration
Last updated
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 Firebase documentation.
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.
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.
2. After the DTDAnalytics initialization block add:
3. To activate the Messaging module, call :
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:
Full example of notification module initialization:
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:
To set a large user icon in the push notification, add:
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)
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:
Run the following code in the in the command line/terminal:
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
):
DTDPushMessage
). Main class propertiesDTDActionButton
)Method | Description |
---|---|
Property | Description |
---|---|
Property | 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
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
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