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

Commit 72aa374

Browse files
authored
Merge pull request #721 from riwu/master
add `checkPermissions` for Android
2 parents c65762a + 5afd96c commit 72aa374

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
@@ -334,9 +334,16 @@ Uses the [ShortcutBadger](https://github.com/leolin310148/ShortcutBadger) on And
334334
## Sending Notification Data From Server
335335
Same parameters as `PushNotification.localNotification()`
336336

337-
## iOS Only Methods
337+
## Checking Notification Permissions
338338
`PushNotification.checkPermissions(callback: Function)` Check permissions
339339

340-
`PushNotification.getApplicationIconBadgeNumber(callback: Function)` get badge number
340+
`callback` will be invoked with a `permissions` object:
341+
- `alert`: boolean
342+
- `badge`: boolean
343+
- `sound`: boolean
344+
345+
## iOS Only Methods
346+
347+
`PushNotification.getApplicationIconBadgeNumber(callback: Function)` Get badge number
341348

342349
`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
@@ -62,7 +62,7 @@ NotificationsComponent.prototype.abandonPermissions = function() {
6262
};
6363

6464
NotificationsComponent.prototype.checkPermissions = function(callback: Function) {
65-
/* Void */
65+
RNPushNotification.checkPermissions().then(alert => callback({ alert }));
6666
};
6767

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

0 commit comments

Comments
 (0)