Skip to content

topl-service / io.matthewnelson.topl_service.notification / ServiceNotification / Builder


class Builder (source)

Where you get to customize how your notification will look and function.

A notification is required to be displayed while TorService is running in the Foreground. Even if you set Builder.showNotification to false, TorService is brought to the Foreground when the user removes your task from the recent apps tray in order to properly shut down Tor and clean up w/o being killed by the OS.

//  private fun generateTorServiceNotificationBuilder(context: Context): ServiceNotification.Builder {
        return ServiceNotification.Builder(
            channelName = "TOPL-Android Demo",
            channelDescription = "TorOnionProxyLibrary-Android Demo",
            channelID = "TOPL-Android Demo",
            notificationID = 615
            .setImageTorNetworkingEnabled(drawableRes = R.drawable.tor_stat_network_enabled)
            .setImageTorNetworkingDisabled(drawableRes = R.drawable.tor_stat_network_disabled)
            .setImageTorDataTransfer(drawableRes = R.drawable.tor_stat_network_dataxfer)
            .setImageTorErrors(drawableRes = R.drawable.tor_stat_notifyerr)
            .setVisibility(visibility = NotificationCompat.VISIBILITY_PRIVATE)
            .setCustomColor(colorRes = R.color.primaryColor)
            .enableTorRestartButton(enable = true)
            .enableTorStopButton(enable = true)
            .showNotification(show = true)

            // Set the notification's contentIntent for when the user clicks the notification
            .also { builder ->
                    ?.let { intent ->

                        // Set in your manifest for the launch activity so the intent won't launch
                        // a new activity over top of your already created activity if the app is
                        // open when the user clicks the notification:
                        // android:launchMode="singleInstance"
                        // For more info on launchMode and Activity Intent flags, see:

                                0, // Your desired request code
                                0 // flags
                            // can also include a bundle if desired
//  }


channelName - Your notification channel’s name (Cannot be Empty).

channelID - Your notification channel’s ID (Cannot be Empty).

channelDescription - Your notification channel’s description (Cannot be Empty).

notificationID - Your foreground notification’s ID.


IllegalArgumentException - If String fields are empty.


Name Summary
<init> Where you get to customize how your notification will look and function.Builder(channelName:String, channelID:String, channelDescription:String, notificationID:Int)


Name Summary
enableTorRestartButton Disabled by Defaultfun enableTorRestartButton(enable:Boolean= true): Builder
enableTorStopButton Disabled by Defaultfun enableTorStopButton(enable:Boolean= true): Builder
setActivityToBeOpenedOnTap Do not use this ~~setActivityToBeOpenedOnTap~~(clazz:Class<*>, intentExtrasKey:String?, intentExtras:String?, intentRequestCode:Int?): Builder
setContentIntent Allows for full control over the PendingIntent used when the user taps the setContentIntent(pendingIntent:PendingIntent?): Builder
setContentIntentData Do not use this ~~setContentIntentData~~(bundle:Bundle?, requestCode:Int?): Builder
setCustomColor Defaults to R.color.tor_service_whitefun setCustomColor(colorRes:Int): Builder
setImageTorDataTransfer Defaults to Orbot/TorBrowser’s icon setImageTorDataTransfer(drawableRes:Int): Builder
setImageTorErrors Defaults to Orbot/TorBrowser’s icon setImageTorErrors(drawableRes:Int): Builder
setImageTorNetworkingDisabled Defaults to Orbot/TorBrowser’s icon setImageTorNetworkingDisabled(drawableRes:Int): Builder
setImageTorNetworkingEnabled Defaults to Orbot/TorBrowser’s icon setImageTorNetworkingEnabled(drawableRes:Int): Builder
setVisibility Defaults to NotificationVisibility.VISIBILITY_SECRETfun setVisibility(visibility:Int): Builder
showNotification Shown by showNotification(show:Boolean= false): Builder