Skip to content

Commit

Permalink
Merge pull request #28 from apptentive/PBI-7369-broadcast-receiver-ex…
Browse files Browse the repository at this point in the history
…ported

PBI-7369-broadcast-receiver-exported
  • Loading branch information
PoornimaApptentive authored Oct 17, 2024
2 parents ea919da + e53d7dd commit 05f3152
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.4.1'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.mparticle:android-kit-plugin:' + project.version
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down Expand Up @@ -48,6 +48,6 @@ allprojects {
}

dependencies {
api 'com.apptentive:apptentive-kit-android:6.7.0'
api 'com.apptentive:apptentive-kit-android:6.9.0'
testImplementation 'io.mockk:mockk:1.13.3'
}
29 changes: 21 additions & 8 deletions src/main/kotlin/com/mparticle/kits/ApptentiveKitUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package com.mparticle.kits

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Context.RECEIVER_EXPORTED
import android.content.Context.RECEIVER_NOT_EXPORTED
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.util.Log
import apptentive.com.android.feedback.Apptentive
import apptentive.com.android.feedback.ApptentiveActivityInfo
import com.mparticle.MParticle
Expand All @@ -12,18 +16,27 @@ import com.mparticle.MParticle
object ApptentiveKitUtils {
@JvmStatic
fun registerApptentiveActivityContext(callback: ApptentiveActivityInfo) {
val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action?.startsWith(MParticle.ServiceProviders.BROADCAST_ACTIVE) == true) {
Apptentive.registerApptentiveActivityInfoCallback(callback)
}
}
}
if (MParticle.getInstance()?.isKitActive(MParticle.ServiceProviders.APPTENTIVE) == true) {
Apptentive.registerApptentiveActivityInfoCallback(callback)
Log.d("ApptentiveKitUtils", "registerApptentiveActivityContext: kit is active")
} else {
val filter =
IntentFilter(MParticle.ServiceProviders.BROADCAST_ACTIVE + MParticle.ServiceProviders.APPTENTIVE);
callback.getApptentiveActivityInfo()?.registerReceiver(object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action?.startsWith(MParticle.ServiceProviders.BROADCAST_ACTIVE) == true) {
Apptentive.registerApptentiveActivityInfoCallback(callback)
}
val filter = IntentFilter(MParticle.ServiceProviders.BROADCAST_ACTIVE + MParticle.ServiceProviders.APPTENTIVE)
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
callback.getApptentiveActivityInfo()
?.registerReceiver(broadcastReceiver, filter, RECEIVER_EXPORTED)
Log.d("ApptentiveKitUtils", "registerApptentiveActivityContext: kit is active SDK 33+")
} else {
callback.getApptentiveActivityInfo()
?.registerReceiver(broadcastReceiver, filter)
Log.d("ApptentiveKitUtils", "registerApptentiveActivityContext: kit is active SDK < 33")
}
}, filter)
}
}
}

0 comments on commit 05f3152

Please sign in to comment.