What is custom tone duration limitation for android and IOS , what will happen custom tone files duration is longer then tone what we have provided?
#android#ios
Answer
Overview
Both Android and iOS have strict limitations on custom notification ringtone file durations. If your custom tone file exceeds these limits, the OS falls back to the default system notification sound.
iOS Custom Tone Limitations
| Property | Limit |
|---|---|
| Max duration | 30 seconds |
| Supported formats | text text text |
| File must be | Bundled in the app (not downloaded at runtime) |
| Location | Must be in the app's main bundle |
dart// Flutter Local Notifications — iOS custom sound NotificationDetails( iOS: DarwinNotificationDetails( sound: 'custom_tone.aiff', // Must be ≤ 30 seconds, in main bundle ), )
iOS Behavior if duration > 30s: The OS silently ignores the custom tone and plays the default system alert sound instead.
Android Custom Tone Limitations
| Property | Details |
|---|---|
| Max duration | No strict OS limit — but practical limit is a few seconds |
| Supported formats | text text text |
| Location | text |
| Notification Channel | Sound is set per channel — cannot change per notification after channel creation |
kotlin// Android — set custom sound on notification channel val sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) val channel = NotificationChannel( "my_channel", "My Channel", NotificationManager.IMPORTANCE_HIGH ).apply { setSound( Uri.parse("android.resource://$packageName/raw/custom_tone"), AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .build() ) }
Flutter Implementation
dart// flutter_local_notifications package const AndroidNotificationDetails androidDetails = AndroidNotificationDetails( 'channel_id', 'Channel Name', sound: RawResourceAndroidNotificationSound('custom_tone'), // no extension importance: Importance.high, priority: Priority.high, ); const DarwinNotificationDetails iosDetails = DarwinNotificationDetails( sound: 'custom_tone.aiff', // ≤ 30 seconds ); const NotificationDetails notificationDetails = NotificationDetails( android: androidDetails, iOS: iosDetails, );
What Happens If Duration Exceeds Limit?
| Platform | Behavior When Tone Too Long |
|---|---|
| iOS | Falls back to default system sound silently |
| Android | May cut off the tone or loop — inconsistent behavior |
Best Practices
- ✅ Keep custom tones under 30 seconds (target 2–5 seconds for notifications)
- ✅ Convert iOS sounds to format for better quality and compatibilitytext
.caf - ✅ Test on actual devices — emulators may behave differently
- ✅ For Android, set the sound at channel creation time — it cannot be changed once the channel exists
- ❌ Do not use long music files as notification sounds