Skip to main content

Notification Integration in Android

Implementation

caution

To use this library it is necessary to have the trust-service.json file with valid access credentials. In case you do not have it, follow the following link

How get trust-service.json file

dependencies {
implementation 'com.trust.notifications:notifications:2.1.22'
}

See the actual version here.

Compatibility

For api >= 26 you must set compatibility with java 1.8

android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

Firebase messaging

Hola

To receive any notification you must integrate firebase library

implementation 'com.google.firebase:firebase-messaging:20.0.0'

For more information about firebase integration see this

Initialize

import ...
public class TestApp extends Application {
@Override
public void onCreate() {
super.onCreate();
TrustNotifications.init(this);
}
}

trust-service.json file

All our services are protected by access tokens, which is why in order to generate a trust id or an notification it is necessary to add a .json file called trust-service inside the assets folder of your android studio project. In order to obtain this file it is necessary to send the following data of your application: bundle_id, app_name and redirect_uri (ex: bundle_id: //auth.id) these data must be sent to app@trust.lat

the structure of the trust-service.json file should be as follows

 {
"client_id": "your_client_id",
"client_secret": "yout_client_secret"
}

Permissions

For the correct use of this library, it is necessary to grant the application overwriting permission

Request the permission

private void openOverlayPermission() {
String PERMISSION_REQUEST_CODE = 9090;
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivityForResult(intent, PERMISSION_REQUEST_CODE);
}

Response of the permission

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
PermissionNotifications.resultPersmission(requestCode, this, new PermissionNotifications.PermissionListener<Boolean>() {
@Override
public void onSuccessPermission(Boolean data) {
//permission granted
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onDeneidPermission(Boolean data) {
//permission deneid
}
});
}

Send a Firebase token

public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Device.saveFirebaseToken(s, this);
}
}

Change then icon of notification

add an image in res-> drawable folder with the follow name:

noti_logo_company

Time

It is possible to configure an available schedule to receive and show notifications To configure a schedule is as follows:

Hawk.put(TIME_START,900);
Hawk.put(TIME_FINISH,2100);

In this example, a time range is being configured from 08:00 AM to 21:00 PM means that notifications will only be shown between that time range.

If a time is not set, notifications will be displayed without time restriction

Dialog Message

image

Banner Message

img_banner.png

Video Message

img_video.png

Notification Message

img_notificacion.png

Block Message

image

Note 1: All the notification should have a "type" property in the main object, this is for different notifications.

Note 2: The color of buttons cannot be empty and must be a HEX color.

Note 3: The URL action in buttons must be a valid URL or the app will crash.

Note 4: you can use HTTP protocol in URL of videos, but need use a "android:usesCleartextTraffic="true" label in the < application> tag inside of your manifest file.