Search code examples
androidmediastore

How to get album artist data without MediaStore.ALBUM_ARTIST


In the app that I'm working on I'm trying to get the Album artist from a song file. I made the query with the cursor and extract the album_artist column (https://stackoverflow.com/a/59631970), but the constant with this String (MediaStore.Audio.AudioColumns.ALBUM_ARTIST) prevent my app from compiling causing a Unresolved reference exception.

The constant has a @hide in its JavaDoc which seems to "hide" the field from outside (couldn't find a legit source to back me up here, I might be very wrong). MediaStore source-code

What is bugging my mind is that the constant exists in the SDK, the column exists (passing the String manually works) and the constant is in the code, so why I cannot use it? If there is a better way what is it? There is no indication in the code and MediaStore.Audio.Albums.ARTIST don't give me the data that I want (gives me the "artist" not the "album artist").

Does someone know what is the proper way to get this data?

(For now I'm leaving the hard-coded String)


Solution

  • One solution is the answer Which might not reliable do what you want, to guarantee reading of album_artist tag, you must read the tag manually through mediaMetadataRetriever.

    You're trying to access a non-sdk interface, those are all methods, constants, classes, etc, that are not referenced in the android documentation. Before android pie (api 28), you could attempt to use and reference these methods trough reflection, but since then google has blacklisted all usage of non-sdk interfaces. The only exception is when using non-sdk interfaces available at an specific api level, but your app must not support any bellow api levels.

    The reason for such change is that non-sdk interfaces are parts of the android ecosystem that must be available at AOSP for some internal reason but are not final or available to the public. Google does not guarantee that any non-sdk interfaces wont change behavior or be deleted, breaking your app. Since developers insisted on using such interfaces in production apps, they decided to rigorously enforce the restriction.

    The @hide annotation in javadoc excludes the code from the compiled javaDoc. So, when google builds its documentation, the constant not being in the android documentation is the intended behavior.

    You can refer to this question question and the documentation

    ps: The constant you want to access will become part of the android sdk after android R