79576328

Date: 2025-04-16 03:10:57
Score: 0.5
Natty:
Report link

Based on my experience, yes, it's definitely possible to get information about currently playing media on Android, though it requires some specific APIs.

The most reliable approach is to use the Media Session API, which lets you discover active media sessions and retrieve their metadata (title, artist, album art, etc.). You'll need to:

Here's what you'll need in your AndroidManifest.xml:
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>

The trickiest part is that you need to implement a NotificationListenerService and request the user to grant notification access to your app - this is unavoidable since reading this data is considered sensitive.

One gotcha: media apps implement these APIs differently, so test with multiple players (Spotify, YouTube Music, etc.) to ensure your app works reliably.

If you run into issues with certain apps, you can fall back to reading media notifications, though that's more fragile.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: dadasese