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
):
Method | Description |
---|---|
| The push notification initialization method |
| The push notification activation method. It passes the |
| A property responsible for the activation/deactivation of push notifications.When the state transitions, it sends a pt with The |
| The method that returns the push module state to |
| The method that returns push registration token to onGetToken callback |
| Used to pass the push notification to the |
| It sets a listener for push notification event trapping |
DTDPushMessage
). Main class propertiesProperty | Description |
---|---|
| Complete information passed with the push notification. |
| The property that returns the value of enum’s Possible values: App - app open Url - external link open Share - share content Deeplink - an in-app link opening |
| The property that returns an optional action identifier |
| Additional data sent to push notification |
DTDActionButton
)Property | Description |
---|---|
| The property that returns the value of enum’s Possible values: App - app open Url - external link open Share - share content Deeplink - an in-app link opening |
| Property that returns an optional action identifier |
| Property that returns the ID of the clicked button |
| Property that returns the text of the clicked button |
| Property that returns the button icon name |
| The button-click app open mode |