Lockscreen Service Notification

Introduction

Buzzscreen uses Foregound Service and in principle, a foreground service results in ongoing notification. Since service notification must be shown when Foreground Service is running, we provide a support class to change notification content so that you can provide more contextually meaningful information for users.

cf) System Notification

On Android OS 8.0 and above, system notification is shown for all apps running in the background. By “running in the background”, it indicates the case when a user escaped from the app’s activity without terminating it, or the app is still running in the background even though the user terminated the app.

System notification is shown from the Android OS, so it is impossible to customize the contents. However, users can turn off the notification on their device - please refer to the blog article.

 

△ (Above: System Notification / Below: Service Notification)

 

Usage

Content

Method & Place

Detail

Example

Content

Method & Place

Detail

Example

Setting and Getting Lock Screen Service Notification Content
recommended

LockerServiceNotificationConfig class enables to get or set service notification content.

You MUST use this class after calling BuzzScreen.init().

Below are components that you can set.

  • Parameters

    • String Title : Title of the notification. Default is the app's name.

    • String Text : Content of the notification. Default is an empty string("").

    • int SmallIcon : Small icon of the notification. Default is the app's icon.

    • int LargeIcon : Large icon of the notification. Default is none.

    • boolean ShowAlways : Boolean value that decides whether or not to show the notification always. You can use it to test your notification setting. Default is false.

    • intent Intent : Intent that defines the action when notification is clicked. Default is to start the Launcher Activity.

 

public class App extends Application { @Override public void onCreate() { super.onCreate(); ... BuzzScreen.init("app_key", this, SimpleLockerActivity.class, R.drawable.image_on_fail, false); // Notification Configuration LockerServiceNotificationConfig config = BuzzScreen.getInstance().getLockerServiceNotificationConfig(); config.setTitle("Sample Title"); config.setText("Sample Text"); config.setSmallIconResourceId(R.drawable.ic_noti_small); config.setLargeIconResourceId(R.drawable.ic_noti_large); // config.setShowAlways(true); } }

 

How to Temporarily Replace Service Notification to Another Notification
optional

BuzzScreen.getInstance.notifyOnServiceNotification(Notification notification)

You must set ShowAlways to trueto use this feature. If not, the method won't work.

 

If your app notifies users of some events using android notification, and at the same time the ongoing notification is also shown, then multiple notifications are shown in the bar. This could be harmful for user experience. Using the method below you can notify event notification on the place where your service notification is, and go back to the original one after user checks it.

  1. Pass your event notification object as the parameter. This notification will be shown on the place of service notification.

  2. To go back to the original service notification (which follows LockerServiceNotificationConfig), call this method again using null as the parameter.