Android
Android Push Notifications
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.

Messaging Module Integration

The Messaging module is available as an AAR (recommended) and JAR library. The library is available in the MavenCentral and GitHub repository.
1. If you use Gradle for the applications build, add mavenCentral() into gradle.build file of your application and specify the following relationship in dependencies block:
defaultConfig {
//other existing fields
versionName "1.0" //your app version (required)
}
dependencies {
// Requirement
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
// if you use AAR (recommended) or JAR downloaded from GitHub, please add:
implementation fileTree(dir: "libs", include: ["*.aar"])
// or just add the dependency, get the latest version from
// https://mvnrepository.com/artifact/com.devtodev/android-analytics
implementation 'com.devtodev:android-analytics:*.*.*'
// https://mvnrepository.com/artifact/com.devtodev/android-messaging
implementation 'com.devtodev:android-messaging:*.*.*'
// Optional (recommended)
implementation 'com.android.installreferrer:installreferrer:2.2'
}
2. To the app manifest add the following:
<application>
<service
android:name="com.devtodev.push.internal.logic.DTDFcmMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver
android:name="com.devtodev.push.internal.logic.PushClickReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.devtodev.android.push.CLICKED" />
</intent-filter>
</receiver>
</application>
3. To add a user icon to your push notification and change its color, 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 add a large user icon to your push notifications, add:
<meta-data
android:name="com.devtodev.push.default_large_icon"
android:resource="@mipmap/ic_large_icon_name"/>
Example:
<application
<!-- Your tags -->
<service
android:name="com.devtodev.push.internal.logic.DTDFcmMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver
android:name="com.devtodev.push.internal.logic.PushClickReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.devtodev.android.push.CLICKED" />
</intent-filter>
</receiver>
<meta-data
android:name="com.devtodev.push.default_small_icon"
android:resource="@drawable/ic_baseline" />
<meta-data
android:name="com.devtodev.push.default_small_icon_color"
android:resource="@color/colorPrimary" />
<meta-data
android:name="com.devtodev.push.default_large_icon"
android:resource="@mipmap/baseline_accessibility_black_18"/>
</application>
4. After the DTDAnalytics initializer, add the DTDMessaging initializer.
Example:
Kotlin
Java
val analyticsConfiguration = DTDAnalyticsConfiguration()
analyticsConfiguration.logLevel = DTDLogLevel.Error
DTDAnalytics.initialize(
appKey = "progectKey",
analyticsConfiguration = analyticsConfiguration,
context = context
)
DTDMessaging.initialize(context = context)
DTDAnalyticsConfiguration analyticsConfiguration = new DTDAnalyticsConfiguration();
analyticsConfiguration.setLogLevel(DTDLogLevel.Error);
DTDAnalytics.INSTANCE.initialize("projectKey",analyticsConfiguration,context);
DTDMessaging.INSTANCE.initialize(context);
5. Subscribe a DTDPushListener to receive information about the DTDMessaging functioning.
Example:
Kotlin
Java
DTDMessaging.setPushListener(object : DTDPushListener {
override fun onPushServiceRegistrationSuccessful(deviceId: String) {
//do something
}
override fun onPushServiceRegistrationFailed(error: String) {
//do something
}
override fun onPushNotificationReceived(message: Map<String, String?>?) {
//do something
}
override fun onPushNotificationOpened(pushMessage: DTDPushMessage, actionButton: DTDActionButton?) {
//do something
}
})
DTDMessaging.INSTANCE.setPushListener(new DTDPushListener() {
@Override
public void onPushServiceRegistrationSuccessful(@NonNull String deviceId) {
//do something
}
@Override
public void onPushServiceRegistrationFailed(@NonNull String error) {
//do something
}
@Override
public void onPushNotificationReceived(@Nullable Map<String, String> message) {
//do something
}
@Override
public void onPushNotificationOpened(@NonNull DTDPushMessage dtdPushMessage, @Nullable DTDActionButton dtdActionButton) {
//do something
}
});
6. Call the DTDMessaging.startPushService() method to activate the Messaging module.

External interface of the DTDMessaging module

Object
Description
DTDMessaging
The main object for push notification initialization.
DTDMessaging.initialize(Context context)
The push notification initialization method.
DTDMessaging.startPushService()
The push notification activation method. It passes the isAllowed current state.
DTDMessaging.pushNotificationsAllowed = true or false
A property responsible for the activation/deactivation of push notifications.
Functions as a getter (describes the current state) and a setter (sets the current state).
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.
DTDMessaging.setIntent(Intent intent)
A method of passing a user intent to the SDK using PushMessage.
Written in the manifest file <meta-data android:name="com.devtodev.push.default_small_icon" android:resource="@drawable/smallIcon" />
Sets a small custom user icon.
Written in the manifest file <meta-data android:name="com.devtodev.default_small_icon_color" android:resource="@color/colorPrimary" />
Sets a color of the small custom user icon.
Written in the manifest file <meta-data android:name="com.devtodev.push.default_large_icon" android:resource="@mipmap/largeIcon" />
Sets a large custom user icon.
DTDMessaging.getToken()
Returns a push notification registration token (firebaseToken).
DTDMessaging.processPushNotification(Context context, RemoteMessage remoteMessage)
Used to pass the push notification to the FirebaseMessagingService if it was implemented by the client but not by the SDK.
DTDMessaging.setPushListener(DTDPushListener pushListener)
(DTDPushListener pushListener) - sets a listener for push notification event trapping.

DTDPushListener Interface Methods

DTDPushListener Interface Methods
Description
onPushServiceRegistrationSuccessful(String deviceId)
Returns a push notification registration token (firebaseToken).
onPushServiceRegistrationFailed(String error)
Returns errors during push notification registration.
onPushNotificationReceived(Map<String, String> message)
Returns a directory with data for improving your push notifications.
onPushNotificationOpened(DTDPushMessage pushMessage, @Nullable DTDActionButton actionButton)
Returns pushMessage and actionButton if they were tapped.

A Class for Receiving Notification Data (DTDPushMessage).

Basic Class Properties

Property
Type
Description
getData()
Map<String, String>
Complete information sent with the use of a remote push notification.
systemId
Int
The notification ID used in the devtodev system.
getTitle(context:Context)
String?
Returns the selected message title or app name if the former is unavailable.
body
String?
The text body.
group
String?
A group of messages.
getSound(context: Context)
Uri?
Returns the storage path of an audio file.
getSoundName()
String?
The notification sound name.
tag
String?
The notification tag.
color
String?
The notification color.
bigPicture
String?
The notification banner if specified.
actionType
DTDActionType
The property that returns an enum’s DTDActionType value.
Possible values:
  • Url - an external link opening
  • Share - content sharing
  • Deeplink - an in-app link opening
actionString
String?
The property that returns an optional action ID.
getIcon(context: Context, userIcon: Int)
Int
The icon resource identifier specified by the user (if specified).
largeIcon
String?
The large notification icon name.
actions
List<DTDActionButton>
The list of action buttons used in the push notification.
isApiSource
Boolean
Specifies whether the push notification was sent using the devtodev API.

A Class for Handling the Notification Button Taps (DTDActionButton)

Property
Type
Description
Id
String?
The property that returns the tapped button ID.
actionString
String?
The property that returns the optional action ID.
actionType
DTDActionType
The property that returns an enum’s DTDActionType value.
Possible values:
  • App - a default value
  • Url - an external link opening
  • Share - content sharing
  • Deeplink - an in-app link opening
icon
String?
The property that returns the button’s icon name.
isBackground
Boolean
The button-click app open mode.
text
String?
The property that returns the text of the tapped button.