Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support detection of blocked channel for Android/Oreo+ #1249

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import android.content.IntentFilter;
import android.os.Bundle;
import androidx.core.app.NotificationManagerCompat;
import android.support.annotation.RequiresApi;
import android.annotation.TargetApi;
import android.app.NotificationChannel;
import android.os.Build;


import com.dieam.reactnativepushnotification.helpers.ApplicationBadgeHelper;
import com.facebook.react.bridge.ActivityEventListener;
Expand All @@ -25,6 +30,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.List;

import android.util.Log;

Expand Down Expand Up @@ -228,4 +234,18 @@ public void clearLocalNotification(int notificationID) {
public void registerNotificationActions(ReadableArray actions) {
registerNotificationsReceiveNotificationActions(actions);
}

@TargetApi(Build.VERSION_CODES.O)
@RequiresApi(api = Build.VERSION_CODES.O)
@ReactMethod
public void isChannelBlocked(String senderID, Promise promise) {
ReactContext reactContext = getReactApplicationContext();

NotificationManager notificationManager =
(NotificationManager) reactContext.getSystemService(reactContext.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = notificationManager.getNotificationChannel(senderID);
Boolean isBlocked = (notificationChannel.getImportance() == NotificationManager.IMPORTANCE_NONE);

promise.resolve(isBlocked);
}
}
8 changes: 8 additions & 0 deletions component/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ NotificationsComponent.prototype.clearAllNotifications = function() {
RNPushNotification.clearAllNotifications()
}

NotificationsComponent.prototype.isChannelBlocked = function(channelId: string, handler: Function) {
RNPushNotification.isChannelBlocked(channelId).then(isBlocked => {
callback(isBlocked)
}).catch(error => {
handler(null, error)
});
};

module.exports = {
state: false,
component: new NotificationsComponent()
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,8 @@ Notifications.clearAllNotifications = function() {
return this.callNative('clearAllNotifications', arguments)
}

Notifications.isChannelBlocked = function() {
return this.callNative('isChannelBlocked', arguments);
};

module.exports = Notifications;