- Overview
- Adding to a project
- Integration
- Registering
- Advanced
- Styling and behaviour
- Unity
- Events
- ProGuard
- FAQs
- Changelog
- License
This is an add-on module for the deltaDNA Android SDK which allows for easy integration of push notifications into a project.
When sending a push notification to clients the implementation will show the message of the notification from the alert
field in the Platform and the application's name as the title, unless a value under the title
key has been added to the push notification's payload. When the notification is tapped by the user the module sends the appropriate events through the SDK.
More details on integration and customization can be found further on in this document.
In your top-level build script:
allprojects {
repositories {
maven {
url 'https://maven.pkg.github.com/deltaDNA/android-sdk'
credentials {
username = "github_username"
password = "github_personal_access_token"
}
}
}
}
In your app's build script:
dependencies {
implementation 'com.deltadna.android:deltadna-sdk:5.0.2'
implementation 'com.deltadna.android:deltadna-sdk-notifications:5.0.2'
}
Once you have the SDK and the Notifications addon in your project you will need to add a NotificationListenerService
definition inside of the application
section
<service
android:name="com.deltadna.android.sdk.notifications.NotificationListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
While the above definition could have been provided by the library this service is quite important as it takes care of showing a notification on the UI when a push message is sent from the Platform, as such we are allowing for customization on how it behaves.
The last step is to add your Application and Sender IDs from the Firebase Console into the manifest file. If your application has been setup using the Google Developer Console then you can easily migrate the project to Firebase by following the instructions here.
<application ...>
...
<meta-data
android:name="ddna_application_id"
android:resource="@string/application_id"/>
<meta-data
android:name="ddna_sender_id"
android:resource="@string/sender_id"/>
</application>
You can always refer to the example implementation here.
In order to register the client for push notifications with the Platform the register()
method needs to be called from DDNANotifications
. This will initiate a request for retrieving a registration token from GCM, and send it to the deltaDNA servers.
A good time to call register()
would be, for example, when the user enables notifications for the application in the settings or when a previous attempt to retrieve the token fails.
It is possible to unregister the client from push notifications by calling unregister()
from DDNANotifications
. If you wish to register later on then register()
should be called.
If you would like to change the style of the notification, for example to use expandable text, the NotificationListenerService
can be extended in order to modify the default behaviour.
An example can be found here. You will also need to change the service
definition in the manifest file to point to the new class.
Changing the style on Unity is a bit more involved, but the steps below describe how to achieve this;
- You will need to checkout the android-sdk project and open it in Android studio. Make sure that you've got all the necessary dependencies downloaded in order to be able to build the project.
- Checkout the version of the project which you need in order to match the version used in the deltaDNA Unity SDK. You can find this out by navigating under
Assets/DeltaDNA/Plugins/Android
(orAssets/Plugins/Android
for newer versions of our Unity SDK) and finding the version of thedeltadna-sdk-notifications-*.aar
file. For example, if the file in the directory was nameddeltadna-sdk-notifications-4.2.3.aar
you would rungit checkout 4.2.3
in theandroid-sdk
project. - Now you can make changes to the
NotificationListenerService
class, either directly or by creating a new class extending from it and overriding the appropriate method. - After you have made the changes you can build the SDK by running
./gradlew clean build check
from the root directory of the project. Once successfully built the new ARR can be copied fromlibrary-notifications/build/outputs/aar
(make sure to use the release version) toAssets/DeltaDNA/Plugins/Android
in order to replace the stock AAR. For newer versions of our Unity SDK you will need to copy the AAR file toAssets/Plugins/Android
and deleteAssets/DeltaDNA/Editor/Android/Dependencies.xml
. If you have made the changes in a new class then you will also need to change the Listener Service entry in the notifications configuration UI for your Unity project to use your new class instead.
The module sends a number of events related to registering for push notifications, posting them on the UI, and listening for user interactions on them. You can listen to these events by extending EventReceiver
and overriding the required methods.
You will need to register your receiver in the manifest file of your application, for example:
<receiver
android:name="your.package.name.YourClassName"
android:exported="false">
<intent-filter>
<action android:name="com.deltadna.android.sdk.notifications.REGISTERED"/>
<action android:name="com.deltadna.android.sdk.notifications.REGISTRATION_FAILED"/>
<action android:name="com.deltadna.android.sdk.notifications.MESSAGE_RECEIVED"/>
<action android:name="com.deltadna.android.sdk.notifications.NOTIFICATION_POSTED"/>
<action android:name="com.deltadna.android.sdk.notifications.NOTIFICATION_OPENED"/>
<action android:name="com.deltadna.android.sdk.notifications.NOTIFICATION_DISMISSED"/>
</intent-filter>
</receiver>
An example implementation of an EventReceiver
can be found here.
There is no need to add additional directives in your ProGuard configuration if you are setting minifyEnabled true
for your application as the library provides its own configuration file which gets included by the Android build tools during the build process.