MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.42k stars 1.37k forks source link

custom sound not working on devices but working in emulator #2287

Closed InShad7 closed 1 month ago

InShad7 commented 3 months ago

path to custom sound android/app/src/main/res/raw/azan.wav

static Future _notificationDetails() async { return const NotificationDetails( android: AndroidNotificationDetails( 'Channel_id_17', 'Channel_name', importance: Importance.high, priority: Priority.high, sound: RawResourceAndroidNotificationSound('azan'), enableVibration: true, playSound: true, ), iOS: DarwinNotificationDetails(sound: 'azan.wav'), ); }

static Future init({bool initSchedule = false}) async { const AndroidInitializationSettings android = AndroidInitializationSettings('@mipmap/ic_launcher');

final DarwinInitializationSettings initializationSettingsDarwin =
    DarwinInitializationSettings(
  requestAlertPermission: true,
  requestBadgePermission: true,
  requestSoundPermission: true,
  onDidReceiveLocalNotification: (id, title, body, payload) => null,
);

final settings = InitializationSettings(
  android: android,
  iOS: initializationSettingsDarwin,
);

await _notifications.initialize(
  settings,
  onDidReceiveNotificationResponse: (details) {
    onNotification.add(details.toString());
  },
);

}

static void showScheduleNotification({ int id = 0, String? title, String? body, String? payload, required DateTime scheduleTime, }) async { try { await _notifications.zonedSchedule( id , title, body, tz.TZDateTime.from(repeatScheduleTime, tz.local), await _notificationDetails(), payload: payload, androidAllowWhileIdle: true, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, matchDateTimeComponents: DateTimeComponents.time, ); } catch (e) { print('Error scheduling notification: $e'); } } }

these are the implementation

working in the emulator with custom sound but in real devices the custom sound is not working but the notifications are coming.

any one know please help me!

mjjoshi commented 3 months ago

same issue while set custom sound if you have any solution then please share

InShad7 commented 3 months ago

same issue while set custom sound if you have any solution then please share

not yet! if you get any solution?

ditheshthegreat commented 3 months ago

For Android 8.0+, sounds and vibrations are associated with notification channels and can only be configured when they are first created. Showing/scheduling a notification will create a channel with the specified id if it doesn't exist already. If another notification specifies the same channel id but tries to specify another sound or vibration pattern then nothing occurs.

refer this link https://pub.dev/packages/flutter_local_notifications#custom-notification-icons-and-sounds

So if you change the custom sound, the app has to be reinstalled to get in same channel

MaikuB commented 2 months ago

Besides what @ditheshthegreat has mentioned, did you check to make sure that you have done release build configuration? If not, then please double check the readme as it's quite possible you missed other steps that are relevant