@@ -12,9 +12,11 @@ import com.segment.analytics.kotlin.core.platform.policies.CountBasedFlushPolicy
12
12
import com.segment.analytics.kotlin.core.platform.policies.FrequencyFlushPolicy
13
13
import com.segment.analytics.kotlin.consent.ConsentManager
14
14
import com.segment.analytics.kotlin.consent.onetrust.OneTrustConsentCategoryProvider
15
+ import com.segment.analytics.kotlin.consent.onetrust.OneTrustConsentChangedNotifier
15
16
import org.json.JSONException
16
17
import org.json.JSONObject
17
18
import sovran.kotlin.SynchronousStore
19
+ import java.lang.ref.WeakReference
18
20
19
21
class MainApplication : Application () {
20
22
@@ -23,6 +25,7 @@ class MainApplication : Application() {
23
25
var appContext: Context ? = null
24
26
private set
25
27
lateinit var analytics: Analytics
28
+ var notifier: OneTrustConsentChangedNotifier ? = null
26
29
27
30
var haveShownOTBanner = false
28
31
lateinit var otPublishersHeadlessSDK: OTPublishersHeadlessSDK
@@ -109,6 +112,18 @@ class MainApplication : Application() {
109
112
Log .d(TAG , " Setting up Analytics with categories: ${categories} " )
110
113
consentCategoryProvider.setCategoryList(categories)
111
114
115
+ // The notifier is used to tell the consent plugin that consent has changed.
116
+ // OneTrust sends out a Broadcast Intent when consent changes. The notifier
117
+ // can be used to start (.register()) or stop (.unregister()) listening for
118
+ // those broadcast. For app, we'll just start it once and not stop it to make
119
+ // sure we we're listening no matter which activity is using the OneTrust UI.
120
+ notifier = OneTrustConsentChangedNotifier (
121
+ WeakReference (this @MainApplication),
122
+ categories,
123
+ consentPlugin)
124
+
125
+ notifier?.register()
126
+
112
127
// This call starts the events following through the ConsentManagement Plugin
113
128
// The plugin will BLOCK all events until start() is called. Here we do it after
114
129
// we have gotten valid information from OneTrust, so you MUST enter valid OneTrust
0 commit comments