Skip to content

Conversation

@gahms
Copy link

@gahms gahms commented Sep 23, 2020

During background operations, the Context received with Registrar.activity() is null. This is also in the doc for Registrar.activity().

The solution is to use an Activity (Registrar.activity()) for requestNotificationPermissions, which will only make sense in the foreground and use a Context (Registrar.context()) for getNotificationPermissionStatus which can also be used during background tasks, such as handling a (silent) push notification.

Use Activity for requestNotificationPermissions which will only make sense in the foreground and use Context for getNotificationPermissionStatus which can also be used during a background task, such as handling a (silent) push notification.
@Vanethos
Copy link
Owner

@gahms I was reading the documentation for the registrar, and in this case does it make more sense to use the activeContext?

https://api.flutter.dev/javadoc/io/flutter/plugin/common/PluginRegistry.Registrar.html#activeContext--

@gahms
Copy link
Author

gahms commented Sep 30, 2020

Yes! You are totally right. I have no idea why I looked at activeContext() and dismissed it. I have tested, and it works great.

@gahms
Copy link
Author

gahms commented Sep 30, 2020

Android Studio tells me I should upgrade the Gradle Plugin used and I am guessing Travis fails due to the use of an old Gradle Plugin - should I upgrade and commit to this PR, open a new PR or just ignore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants