diff --git a/android/src/main/java/changjoopark/com/flutter_foreground_plugin/FlutterForegroundPlugin.java b/android/src/main/java/changjoopark/com/flutter_foreground_plugin/FlutterForegroundPlugin.java index 01558ff..a3146f5 100644 --- a/android/src/main/java/changjoopark/com/flutter_foreground_plugin/FlutterForegroundPlugin.java +++ b/android/src/main/java/changjoopark/com/flutter_foreground_plugin/FlutterForegroundPlugin.java @@ -69,27 +69,28 @@ public static void registerWith(Registrar registrar) { @Override public void onMethodCall(MethodCall call, Result result) { - switch (call.method) { - case "startForegroundService": - final Boolean holdWakeLock = call.argument("holdWakeLock"); - final String icon = call.argument("icon"); - final int color = call.argument("color"); - final String title = call.argument("title"); - final String content = call.argument("content"); - final String subtext = call.argument("subtext"); - final Boolean chronometer = call.argument("chronometer"); - final Boolean stopAction = call.argument("stop_action"); - final String stopIcon = call.argument("stop_icon"); - final String stopText = call.argument("stop_text"); - - launchForegroundService(icon, color, title, content, subtext, chronometer, stopAction, stopIcon, stopText); - result.success("startForegroundService"); - break; - case "stopForegroundService": - stopForegroundService(); - result.success("stopForegroundService"); - break; - case "setServiceMethodInterval": + switch (call.method) { + case "startForegroundService": + final Boolean holdWakeLock = call.argument("holdWakeLock"); + final String icon = call.argument("icon"); + final int color = call.argument("color"); + final String title = call.argument("title"); + final String content = call.argument("content"); + final String subtext = call.argument("subtext"); + final Boolean chronometer = call.argument("chronometer"); + final Boolean stopAction = call.argument("stop_action"); + final String stopIcon = call.argument("stop_icon"); + final String stopText = call.argument("stop_text"); + final String channelId = call.argument("channel_id"); + + launchForegroundService(icon, color, title, content, subtext, chronometer, stopAction, stopIcon, stopText,channelId); + result.success("startForegroundService"); + break; + case "stopForegroundService": + stopForegroundService(); + result.success("stopForegroundService"); + break; + case "setServiceMethodInterval": if (call.argument("seconds") == null) { result.notImplemented(); break; @@ -118,7 +119,8 @@ public void onMethodCall(MethodCall call, Result result) { private void launchForegroundService(String icon, int color, String title, String content, String subtext, Boolean chronometer, Boolean stopAction, String stopIcon, - String stopText) { + + String stopText,String channelId) { Intent intent = new Intent(context, FlutterForegroundService.class); intent.setAction(START_FOREGROUND_ACTION); intent.putExtra("icon", icon); @@ -130,6 +132,7 @@ private void launchForegroundService(String icon, int color, String title, Strin intent.putExtra("stop_action", stopAction); intent.putExtra("stop_icon", stopIcon); intent.putExtra("stop_text", stopText); + intent.putExtra("channel_id", channelId); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { context.startForegroundService(intent); diff --git a/android/src/main/java/changjoopark/com/flutter_foreground_plugin/FlutterForegroundService.java b/android/src/main/java/changjoopark/com/flutter_foreground_plugin/FlutterForegroundService.java index d0de7b5..04208ef 100644 --- a/android/src/main/java/changjoopark/com/flutter_foreground_plugin/FlutterForegroundService.java +++ b/android/src/main/java/changjoopark/com/flutter_foreground_plugin/FlutterForegroundService.java @@ -46,7 +46,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, - "flutter_foreground_service_channel", + bundle.getString("channel_id"), NotificationManager.IMPORTANCE_DEFAULT); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) diff --git a/example/lib/main.dart b/example/lib/main.dart index 6735e37..de0db3e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,5 +1,4 @@ import 'dart:io'; - import 'package:flutter/material.dart'; import 'package:flutter_foreground_plugin/flutter_foreground_plugin.dart'; @@ -69,6 +68,7 @@ void startForegroundService() async { title: "Flutter Foreground Service", content: "This is Content", iconName: "ic_stat_hot_tub", + channelId: "MY_CHANNEL_ID", ); } diff --git a/lib/flutter_foreground_plugin.dart b/lib/flutter_foreground_plugin.dart index 6782b83..fe51863 100644 --- a/lib/flutter_foreground_plugin.dart +++ b/lib/flutter_foreground_plugin.dart @@ -28,6 +28,7 @@ class FlutterForegroundPlugin { bool stopAction = false, String? stopIcon, String stopText = 'Close', + String channelId = 'flutter_foreground_notification_channel', }) async { if (onStarted != null) { onStartedMethod = onStarted; @@ -48,6 +49,7 @@ class FlutterForegroundPlugin { 'stop_action': stopAction, 'stop_icon': stopIcon, 'stop_text': stopText, + 'channel_id': channelId, }); }