Can one "unhide" hidden methods?


I am working on an Android application which is recording and playing audio. To create more friendly log-messages I would like to use this method from class android.media.AudioFormat`:

/** @hide */
public static String toLogFriendlyEncoding(int enc) {...}

It returns "human-readable" descriptions of the encoding constants being used. However, because the method is annotated with @hide, AndroidStudio throws an error when compiling my code:

Log.d(TAG, "encoding: " + AudioFormat.toLogFriendlyEncoding(AUDIO_ENCODING));

Can one overrule this @hide-annotation somehow? I really see no point in copy-pasting and recreating this method locally. It also poses no security- or other risk and creating a local copy might create code that gets out-of-sync with the actual implementation over time...

2
May 1 at 5:35 PM
User Avatarmmo
#java#android

Accepted Answer

> Can one overrule this @hide-annotation somehow?

You might be able to get past it via reflection. That will depend on whether or not it is on the restricted list.

> creating a local copy might create code that gets out-of-sync with the actual implementation over time

On the flip side, you assume that this undocumented-and-unavailable method exists on all devices, which may not be the case. Device manufacturers routinely change Android's non-public API. How many have messed with this particular method is anyone's guess.

User AvatarCommonsWare
May 1 at 5:47 PM
3