Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
InShad7 opened this issue Mar 31, 2024 · 4 comments
Open

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

InShad7 opened this issue Mar 31, 2024 · 4 comments

Comments

@InShad7
Copy link

InShad7 commented Mar 31, 2024

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
Copy link

mjjoshi commented Apr 2, 2024

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

@InShad7
Copy link
Author

InShad7 commented Apr 15, 2024

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

not yet!
if you get any solution?

@ditheshthegreat
Copy link
Contributor

ditheshthegreat commented Apr 16, 2024

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
Copy link
Owner

MaikuB commented May 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants