flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

custom sound not working on devices but working in emulator

Open InShad7 opened this issue 10 months ago • 3 comments

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

static Future<NotificationDetails> _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!

InShad7 avatar Mar 31 '24 06:03 InShad7

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

mjjoshi avatar Apr 02 '24 09:04 mjjoshi

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

not yet! if you get any solution?

InShad7 avatar Apr 15 '24 05:04 InShad7

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

ditheshthegreat avatar Apr 16 '24 10:04 ditheshthegreat

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

MaikuB avatar May 17 '24 10:05 MaikuB