Skip to content

Commit

Permalink
Merge pull request #1935 from OneSignal/crash-bindService-with-Broadc…
Browse files Browse the repository at this point in the history
…ast-Context

Crash on bindService with broadcast receiver context
  • Loading branch information
jinliu9508 committed Jan 31, 2024
2 parents 4af2ff5 + e612320 commit d7ffed0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ internal class TrackGooglePurchase(
mServiceConn = serviceConn
val serviceIntent = Intent("com.android.vending.billing.InAppBillingService.BIND")
serviceIntent.setPackage("com.android.vending")
_applicationService.appContext.bindService(serviceIntent, serviceConn, Context.BIND_AUTO_CREATE)
// Invoke 'applicationContext' to avoid exceptions caused by 'ReceiverRestrictedContext' when using 'bindService'.
_applicationService.appContext.applicationContext.bindService(serviceIntent, serviceConn, Context.BIND_AUTO_CREATE)
} else if (mIInAppBillingService != null) {
queryBoughtItems()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BootUpReceiver : BroadcastReceiver() {
context: Context,
intent: Intent,
) {
if (!OneSignal.initWithContext(context)) {
if (!OneSignal.initWithContext(context.applicationContext)) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FCMBroadcastReceiver : BroadcastReceiver() {
return
}

if (!OneSignal.initWithContext(context)) {
if (!OneSignal.initWithContext(context.applicationContext)) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class UpgradeReceiver : BroadcastReceiver() {
return
}

if (!OneSignal.initWithContext(context)) {
if (!OneSignal.initWithContext(context.applicationContext)) {
return
}

Expand Down

0 comments on commit d7ffed0

Please sign in to comment.