From 3cf941e691c0981561d48f8c2b8a8240184ea5c8 Mon Sep 17 00:00:00 2001 From: Remigijus Kiminas Date: Thu, 9 Dec 2021 09:40:18 -0500 Subject: [PATCH] Android notifications channels support --- android/app/build.gradle | 8 ++-- lib/utils/local_notification.dart | 69 +++++++++++++++++++++++++------ pubspec.lock | 0 pubspec.yaml | 8 ++-- 4 files changed, 64 insertions(+), 21 deletions(-) mode change 100644 => 100755 android/app/build.gradle mode change 100644 => 100755 pubspec.lock mode change 100644 => 100755 pubspec.yaml diff --git a/android/app/build.gradle b/android/app/build.gradle old mode 100644 new mode 100755 index 3bd55e4..9e6900f --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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' @@ -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" } diff --git a/lib/utils/local_notification.dart b/lib/utils/local_notification.dart index 0a55ba9..7140b1d 100644 --- a/lib/utils/local_notification.dart +++ b/lib/utils/local_notification.dart @@ -8,6 +8,7 @@ import 'package:rxdart/subjects.dart'; import 'package:livehelp/model/model.dart'; + class LocalNotificationPlugin { // FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; @@ -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() { diff --git a/pubspec.lock b/pubspec.lock old mode 100644 new mode 100755 diff --git a/pubspec.yaml b/pubspec.yaml old mode 100644 new mode 100755 index 2ca15eb..1ca409b --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 @@ -29,6 +29,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + test: ^1.15.4 flutter_launcher_icons: "^0.6.1" @@ -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" \ No newline at end of file + # see https://flutter.io/custom-fonts/#from-packages \ No newline at end of file