Third-party persistent notification
To use your application persistent foreground notification instead of the Sense360 Traveling Foreground notification, you must pass a a valid Notification ID.
This notification must be always-on and persistent, with an importance level of at least IMPORTANCE_LOW. When providing the third_party_notification_id
, the SDK attempts to use the application foreground notification instead of its own, and, as such, will not use the other values set for title, text, or click-action.
If the notification associated with the third_party_notification_id
is unavailable, the SDK defaults to display its own notification with the details configured in the AndroidManifest.xml
and updateForegroundService()
call. This notification ID is entirely optional and not required for complete functionality of the SDK.
<!-- Optional: Do not include this field unless the App has a persistent foreground notification.
Whether to use the application existing foreground notification via its Notification ID -->
<meta-data
android:name="com.sense360.third_party_notification_id"
android:value="123456" />
To dynamically set and update the Notification ID within your application code, use the ForegroundServiceConfig
object as shown below.
clickOpensApp
, newTitle
, and newMessage
parameters in case the app persistent notification is not displayed.boolean isEnabled = true;
Boolean clickOpensApp = false;
String newTitle = "Searching for surveys...";
String newMessage = "Searching for location based surveys...";
int notificationId = 123456;
ForegroundServiceConfig newConfig = new ForegroundServiceConfig(isEnabled, clickOpensApp, newTitle, newMessage, notificationId);
//Replace "ic_notification_icon" with your notification icon's name.
newConfig.passNotificationIconId(R.drawable.ic_notification_icon);
Sense360.updateForegroundService(getActivity().getApplicationContext(), newConfig);
Third-party persistent notification with enable/disable
Follow the steps below to implement third-party persistent notification with enable
On application start, or when being brought into the foreground:
The notification disappears, so the application must notify Sense360 to stop associated background services.
- Sense360 has a
BroadcastReceiver
, theForegroundNotificationDeleteReceiver
, to handle this:sendBroadcast(new Intent(context, ForegroundNotificationDeleteReceiver.class));
On application close, or when being moved into the background:
The notification is created, so the application must notify Sense360 to allow its services to run in the foreground.
- Notify Sense360 via this code line:
Sense360.notifyForegroundNotificationAvailable(context);
Testing Third-party persistent notification
To test the foreground service notification, call this method:
Sense360Testing.triggerForegroundService(getApplicationContext());
Consider to:
Call
Sense360.start()
at some point before callingtriggerForegroundService()
. Additionally, make sure that the application persistent notification is displayed when calling this method.If the
third_party_notification_id
is properly specified, there is no additional notification displayed besides the application persistent notification. If another Foreground notification appears, this indicates the Sense360 SDK does not have access to the application notification and the integration was not successful.Remove the call to
Sense360Testing.triggerForegroundService
from any production build – this call is only used for integration testing.