Android 14 introduced strict requirements for foreground services. You can no longer just start a service; you must declare its type and the corresponding permissions, or your app will crash immediately on target SDK 34.
The New Declaration
You must specify android:foregroundServiceType in your manifest for every service that
calls startForeground().
<service
android:name=".MyMusicService"
android:foregroundServiceType="mediaPlayback"
android:exported="false" />
Required Permissions
Depending on the type, you need specific permissions. For mediaPlayback, you need
FOREGROUND_SERVICE_MEDIA_PLAYBACK. For data sync, you need
FOREGROUND_SERVICE_DATA_SYNC.
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
Runtime Considerations
Starting with API 34, Android also enforces that you call startForeground() within 10
seconds of the service starting, or it will be killed. Always ensure your notification is ready
before starting the service.
Summary
API 34 is all about transparency. Declare your service types, request the right permissions, and keep your background work honest!