Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 5afd96c

Browse files
committed
add checkPermissions for Android
1 parent 5b34f15 commit 5afd96c

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,16 @@ Uses the [ShortcutBadger](https://github.com/leolin310148/ShortcutBadger) on And
317317
## Sending Notification Data From Server
318318
Same parameters as `PushNotification.localNotification()`
319319

320-
## iOS Only Methods
320+
## Checking Notification Permissions
321321
`PushNotification.checkPermissions(callback: Function)` Check permissions
322322

323-
`PushNotification.getApplicationIconBadgeNumber(callback: Function)` get badge number
323+
`callback` will be invoked with a `permissions` object:
324+
- `alert`: boolean
325+
- `badge`: boolean
326+
- `sound`: boolean
327+
328+
## iOS Only Methods
329+
330+
`PushNotification.getApplicationIconBadgeNumber(callback: Function)` Get badge number
324331

325332
`PushNotification.abandonPermissions()` Abandon permissions

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.content.Intent;
99
import android.content.IntentFilter;
1010
import android.os.Bundle;
11+
import android.support.v4.app.NotificationManagerCompat;
1112

1213
import com.dieam.reactnativepushnotification.helpers.ApplicationBadgeHelper;
1314
import com.facebook.react.bridge.ActivityEventListener;
@@ -105,6 +106,13 @@ public void onReceive(Context context, Intent intent) {
105106
}, intentFilter);
106107
}
107108

109+
@ReactMethod
110+
public void checkPermissions(Promise promise) {
111+
ReactContext reactContext = getReactApplicationContext();
112+
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(reactContext);
113+
promise.resolve(managerCompat.areNotificationsEnabled());
114+
}
115+
108116
@ReactMethod
109117
public void requestPermissions(String senderID) {
110118
ReactContext reactContext = getReactApplicationContext();

component/index.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ NotificationsComponent.prototype.abandonPermissions = function() {
5858
};
5959

6060
NotificationsComponent.prototype.checkPermissions = function(callback: Function) {
61-
/* Void */
61+
RNPushNotification.checkPermissions().then(alert => callback({ alert }));
6262
};
6363

6464
NotificationsComponent.prototype.addEventListener = function(type: string, handler: Function) {

0 commit comments

Comments
 (0)