Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBI-7369-broadcast-receiver-exported #28

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}