From 555bb1f9bd02ccd999891a316e7ee0f8c1844e92 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Thu, 24 Jun 2021 16:59:18 +0200 Subject: [PATCH] fix(local-notifications): requestPermissions and checkPermissions return if enabled (#494) --- .../LocalNotificationsPlugin.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java index 83d6a2d28..d77a65595 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java @@ -112,6 +112,28 @@ public void listChannels(PluginCall call) { notificationChannelManager.listChannels(call); } + @PluginMethod + public void checkPermissions(PluginCall call) { + JSObject permissionsResultJSON = new JSObject(); + permissionsResultJSON.put("display", getNotificationPermissionText()); + call.resolve(permissionsResultJSON); + } + + @PluginMethod + public void requestPermissions(PluginCall call) { + JSObject permissionsResultJSON = new JSObject(); + permissionsResultJSON.put("display", getNotificationPermissionText()); + call.resolve(permissionsResultJSON); + } + + private String getNotificationPermissionText() { + if (manager.areNotificationsEnabled()) { + return "granted"; + } else { + return "denied"; + } + } + public static void fireReceived(JSObject notification) { LocalNotificationsPlugin localNotificationsPlugin = LocalNotificationsPlugin.getLocalNotificationsInstance(); if (localNotificationsPlugin != null) {