From 4356b4f0ea89f3358bad56ddeb22fa6572e918f8 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 25 Mar 2020 10:10:20 +0100 Subject: [PATCH] add android push customization --- .../kotlin/com/example/example/Application.kt | 3 +++ example/lib/main.dart | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/example/android/app/src/main/kotlin/com/example/example/Application.kt b/example/android/app/src/main/kotlin/com/example/example/Application.kt index 247fdcf8..dfe01b38 100644 --- a/example/android/app/src/main/kotlin/com/example/example/Application.kt +++ b/example/android/app/src/main/kotlin/com/example/example/Application.kt @@ -1,5 +1,6 @@ package com.example.example +import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin import com.example.path_provider.PathProviderPlugin import io.flutter.app.FlutterApplication import io.flutter.plugin.common.PluginRegistry @@ -15,6 +16,8 @@ class Application : FlutterApplication(), PluginRegistrantCallback { } override fun registerWith(registry: PluginRegistry?) { + FlutterLocalNotificationsPlugin.registerWith(registry?.registrarFor( + "com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin")) SharedPreferencesPlugin.registerWith(registry?.registrarFor( "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")) FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin")) diff --git a/example/lib/main.dart b/example/lib/main.dart index 9d8dc1fa..247ef027 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,10 +1,35 @@ import 'package:flutter/material.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +Future _handleBackgroundNotification( + Map notification, +) async { + final notificationData = await NotificationService.storeMessage(notification); + + final androidPlatformChannelSpecifics = AndroidNotificationDetails( + 'Message notifications', + 'Message notifications', + 'Channel dedicated to message notifications', + importance: Importance.Max, + priority: Priority.High, + ); + + final androidNotificationOptions = AndroidNotificationOptions( + androidNotificationDetails: androidPlatformChannelSpecifics, + id: notificationData.message.id.hashCode, + title: + 'CUSTOM ${notificationData.message.user.name} @ ${notificationData.channel.cid}', + body: notificationData.message.text, + ); + + await NotificationService.sendNotification(androidNotificationOptions); +} + void main() async { final client = Client( 's2dxdhpxd94g', logLevel: Level.INFO, + notificationHandler: _handleBackgroundNotification, ); await client.setUser(