Add Android API to delete channel and channel group

This commit is contained in:
Dariusz Luksza 2018-05-13 22:16:46 +02:00
parent bcd655d765
commit 57901cd29a
4 changed files with 54 additions and 0 deletions

View File

@ -129,6 +129,18 @@ public class RNFirebaseNotificationManager {
}
}
public void deleteChannelGroup(String groupId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.deleteNotificationChannelGroup(groupId);
}
}
public void deleteChannel(String channelId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.deleteNotificationChannel(channelId);
}
}
public void displayNotification(ReadableMap notification, Promise promise) {
Bundle notificationBundle = Arguments.toBundle(notification);
displayNotification(notificationBundle, promise);

View File

@ -157,6 +157,18 @@ public class RNFirebaseNotifications extends ReactContextBaseJavaModule implemen
notificationManager.createChannels(channelsArray);
promise.resolve(null);
}
@ReactMethod
public void deleteChannelGroup(String channelId, Promise promise) {
notificationManager.deleteChannelGroup(channelId);
promise.resolve(null);
}
@ReactMethod
public void deleteChannel(String channelId, Promise promise) {
notificationManager.deleteChannel(channelId);
promise.resolve(null);
}
//////////////////////////////////////////////////////////////////////
// End Android specific methods
//////////////////////////////////////////////////////////////////////

2
lib/index.d.ts vendored
View File

@ -1097,6 +1097,8 @@ declare module 'react-native-firebase' {
channelGroups: Android.ChannelGroup[]
): Promise<void>;
createChannels(channels: Android.Channel[]): Promise<void>;
deleteChannelGroup(groupId: string): Promise<void>;
deleteChannel(channelId: string): Promise<void>;
}
interface Notifications {

View File

@ -91,4 +91,32 @@ export default class AndroidNotifications {
}
return Promise.resolve();
}
deleteChannelGroup(groupId: string): Promise<void> {
if (Platform.OS === 'android') {
if (typeof groupId !== 'string') {
throw new Error(
`AndroidNotifications:deleteChannelGroup expects an 'string' but got type ${typeof groupId}`
);
}
return getNativeModule(this._notifications).deleteChannelGroup(
groupId
);
}
return Promise.resolve();
}
deleteChannel(channelId: string): Promise<void> {
if (Platform.OS === 'android') {
if (typeof channelId !== 'string') {
throw new Error(
`AndroidNotifications:deleteChannel expects an 'string' but got type ${typeof channelId}`
);
}
return getNativeModule(this._notifications).deleteChannel(
channelId
);
}
return Promise.resolve();
}
}