Skip to content

Commit

Permalink
Android notifications channels support
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Dec 9, 2021
1 parent 215f9fb commit 3cf941e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 21 deletions.
8 changes: 4 additions & 4 deletions android/app/build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
compileSdkVersion 29
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -44,9 +44,9 @@ android {
// TODO: Specify your own unique Application.kt ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.livehelperchat.chat"
minSdkVersion 16
targetSdkVersion 29
versionCode 35
versionName "1.6"
targetSdkVersion 30
versionCode 36
versionName "1.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
69 changes: 57 additions & 12 deletions lib/utils/local_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:rxdart/subjects.dart';

import 'package:livehelp/model/model.dart';


class LocalNotificationPlugin {
//
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
Expand All @@ -26,45 +27,89 @@ class LocalNotificationPlugin {

if (Platform.isIOS) {
_requestIOSPermission();
} else {

const AndroidNotificationChannel channel = AndroidNotificationChannel(
'com.livehelperchat.chat.channel.NEWCHAT', // id
'New chat (background)', // title
'New chat notifications while app is in the background', // description
importance: Importance.High,
enableVibration: true,
playSound: true,
);

const AndroidNotificationChannel channelMessage = AndroidNotificationChannel(
'com.livehelperchat.chat.channel.NEWMESSAGE', // id
'New messages (background)', // title
'New chat messages notifications while app is in the background', // description
importance: Importance.High,
enableVibration: true,
playSound: true,
);

const AndroidNotificationChannel channelGroupMessage = AndroidNotificationChannel(
'com.livehelperchat.chat.channel.NEWGROUPMESSAGE', // id
'New group messages (background)', // title
'New group messages notifications while app is in the background', // description
importance: Importance.High,
enableVibration: true,
playSound: true,
);

flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);

flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channelMessage);

flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channelGroupMessage);
}

initializePlatformSpecifics();
}

// default channel id - same as in AndroidManifest.xml file
static final NotificationChannel channelDefault = NotificationChannel(
id: "com.livehelperchat.chat.channel.lhcmessenger_notification",
name: "Information",
description: "Info from server",
name: "Default",
description: "Default notifications while app is open",
number: 1001);

static final NotificationChannel silentChannel = NotificationChannel(
id: "com.livehelperchat.chat.channel.lhc_silent_channel",
name: "Information",
description: "Info from server",
name: "Default",
description: "Default notifications while app is open",
number: 1001);

static final NotificationChannel channelNewChat = NotificationChannel(
id: "com.livehelperchat.chat.channel.NEWCHAT",
name: "New Chat",
description: "New Chat",
name: "New chat (open app)",
description: "New chat notifications while app is open",
number: 1111);

static final NotificationChannel channelNewMsg = NotificationChannel(
id: "com.livehelperchat.chat.channel.NEWMESSAGE",
name: "New Messages",
description: "New Messages",
name: "New messages (open app)",
description: "New messages notifications while app is open",
number: 2222);

static final NotificationChannel channelUnreadMsg = NotificationChannel(
id: "com.livehelperchat.chat.channel.UNREADMSG",
name: "Unread Messages",
description: "Unread Messages",
name: "Unread messages (open app)",
description: "Unread messages notifications while app is open",
number: 3333);

static final NotificationChannel channelNewGroupMsg = NotificationChannel(
id: "com.livehelperchat.chat.channel.NEWGROUPMESSAGE",
name: "New group Messages",
description: "New group Messages",
name: "New group messages (open app)",
description: "New group messages notifications while app is open",
number: 4444);

initializePlatformSpecifics() {
Expand Down
Empty file modified pubspec.lock
100644 → 100755
Empty file.
8 changes: 3 additions & 5 deletions pubspec.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: livehelp
description: A messenger for Live Helper Chat
version: 1.0.12+12
version: 1.0.13+13
dependencies:
flutter:
sdk: flutter
Expand Down Expand Up @@ -29,6 +29,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
test: ^1.15.4

flutter_launcher_icons: "^0.6.1"

Expand Down Expand Up @@ -76,7 +77,4 @@ flutter:
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages
environment:
sdk: '>=2.0.0 <3.0.0'
flutter: "1.24.0-3.0.pre"
# see https://flutter.io/custom-fonts/#from-packages

0 comments on commit 3cf941e

Please sign in to comment.