OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

[Bug]: optedIn is not being updated accordingly on Android

Open luanalbineli opened this issue 5 months ago • 1 comments
trafficstars

What happened?

We have a screen where the user can opt in/out to push notifications. To get the current opt value, we use the following code (assuming that notification permissions are granted):

OneSignal.User.pushSubscription.optedIn

To opt in/out, we are using the following code (depending on user's choice):

// Opt out.
await OneSignal.User.pushSubscription.optOut();

// Opt in.
await OneSignal.User.pushSubscription.optIn();

After we close/open the app, or sometimes after a Hot Restart, the optedIn property no longer gets updated properly, after the opt in/out call.

On the background, the operation is enqueued and executed properly:

[main] OperationRepo.enqueue(operation: {"name":"update-subscription","appId":"APP_ID","onesignalId":
"ONE_SIGNAL_ID","subscriptionId":"SUB_ID","type":"PUSH","enabled":true,"address":"ADDRESS",
"status":"SUBSCRIBED"}, flush: false)

[DefaultDispatcher-worker-8] HttpClient: Request Sent = PATCH https://api.onesignal.com/apps/{APP_ID}/subscriptions/{SUB_ID}
Body: {"subscription":{"type":"AndroidPush","token":"TOKEN","enabled":true...}

On the example above, I've tried to opt in. I called await OneSignal.User.pushSubscription.optIn();, closed the screen, opened again, and the optedIn was still false.

I'm currently running the tests on a Physical Android device (Samsung S21 Ultra).

Steps to reproduce?

1. Install version 5.3.0.
2. Android user opens the app (with notification permissions granted).
3. User opt out from notifications.
4. User restarts the app.
4. User opt in.

What did you expect to happen?

OneSignal.User.pushSubscription.optedIn should be true. Instead is false.

OneSignal Flutter SDK version

5.3.0

Which platform(s) are affected?

  • [ ] iOS
  • [x] Android

Relevant log output


Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

luanalbineli avatar Jun 13 '25 11:06 luanalbineli

same problem here in 5.3.3

the optIn() is done with success (push notifications accepted) but right after, and even with delay or retry, the optIN stays false or null

and by the way it works well on iOS

O-Nicks avatar Jun 20 '25 09:06 O-Nicks