Skip to content

Commit 7e72e36

Browse files
committed
creating response handler for push prompting
1 parent bd99631 commit 7e72e36

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ private void userProvidedPrivacyConsent(MethodCall call, Result reply) {
279279

280280
private void promptPermission(MethodCall call, Result result) {
281281
boolean fallback = call.argument("fallback");
282-
OneSignal.promptForPushNotifications(fallback);
283-
replySuccess(result, null);
282+
OneSignal.promptForPushNotifications(fallback, new OSFlutterPromptForPushNotificationPermissionResponseHandler(messenger, channel, result, "promptPermission"));
284283
}
285284

286285
private void getDeviceState(Result reply) {
@@ -568,6 +567,22 @@ public void onFailure(OneSignal.ExternalIdError error) {
568567
}
569568
}
570569

570+
static class OSFlutterPromptForPushNotificationPermissionResponseHandler extends OSFlutterHandler
571+
implements OneSignal.PromptForPushNotificationPermissionResponseHandler {
572+
OSFlutterPromptForPushNotificationPermissionResponseHandler(BinaryMessenger messenger, MethodChannel channel, Result res, String methodName) {
573+
super(messenger, channel, res, methodName);
574+
}
575+
576+
@Override
577+
public void response(boolean accepted) {
578+
if (this.replySubmitted.getAndSet(true)) {
579+
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "OneSignal " + methodName + " handler called twice, ignoring! response");
580+
return;
581+
}
582+
replySuccess(result, accepted);
583+
}
584+
}
585+
571586
static class OSFlutterPostNotificationHandler extends OSFlutterHandler
572587
implements OneSignal.PostNotificationResponseHandler {
573588

0 commit comments

Comments
 (0)