Skip to content

Commit

Permalink
Fix RECEIVER_NOT_EXPORTED
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Jan 17, 2024
1 parent a11b72b commit 4a4425f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.os.PowerManager
import androidx.core.content.ContextCompat
import info.mqtt.android.service.room.MqMessageDatabase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -554,7 +555,10 @@ class MqttService : Service(), MqttTraceHandler {
private fun registerBroadcastReceivers() {
if (networkConnectionMonitor == null) {
networkConnectionMonitor = NetworkConnectionIntentReceiver()
registerReceiver(networkConnectionMonitor, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
ContextCompat.registerReceiver(
this, networkConnectionMonitor, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION),
ContextCompat.RECEIVER_NOT_EXPORTED
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.content.IntentFilter
import android.os.Build
import android.os.PowerManager
import android.os.SystemClock
import androidx.core.content.ContextCompat
import info.mqtt.android.service.MqttService
import info.mqtt.android.service.MqttServiceConstants
import kotlinx.coroutines.*
Expand Down Expand Up @@ -52,7 +53,7 @@ internal class AlarmPingSender(val service: MqttService) : MqttPingSender {
override fun start() {
val action = MqttServiceConstants.PING_SENDER + clientComms!!.client.clientId
Timber.d("Register AlarmReceiver to MqttService$action")
service.registerReceiver(alarmReceiver, IntentFilter(action))
ContextCompat.registerReceiver(service, alarmReceiver, IntentFilter(action), ContextCompat.RECEIVER_NOT_EXPORTED)
pendingIntent = PendingIntent.getBroadcast(service, 0, Intent(action), pendingIntentFlags)
schedule(clientComms!!.keepAlive)
hasStarted = true
Expand Down

0 comments on commit 4a4425f

Please sign in to comment.