Skip to content

Commit 58e4661

Browse files
committed
Android: Resolve request permission when already true
Problem: If permission is already enabled, the native call to `OneSignal.getNotifications().requestPermission(fallbackToSettings, Continue.with(...)` never suspends and the Continuation code block never runs. As a result, we would not be able to resolve the promise over the bridge. Solution: Before calling that method, do a permission check and return true. Opt to check the permission in Android instead of resolving early in Dart because the permission boolean may not be initialized correctly yet when requestPermission is called soon after initialization.
1 parent 2d07082 commit 58e4661

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

android/src/main/java/com/onesignal/flutter/OneSignalNotifications.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ else if (call.method.contentEquals("OneSignal#addNativeClickListener"))
7878

7979
private void requestPermission(MethodCall call, Result result) {
8080
boolean fallback = (boolean) call.argument("fallbackToSettings");
81+
// if permission already exists, return early as the method call will not resolve
82+
if (OneSignal.getNotifications().getPermission()) {
83+
replySuccess(result, true);
84+
return;
85+
}
86+
8187
OneSignal.getNotifications().requestPermission(fallback, Continue.with(permissionResult -> {
8288
replySuccess(result, permissionResult.getData());
8389
}));

0 commit comments

Comments
 (0)