At the Session Initiation stage (INVITE), the clients (sip/voip stack) exposes to the SIP Proxy or Gateway what codecs it can use, in this case, the Android Native SIP/RTP stack can use, G711, AMR, GSM, in a prioritized list, the SIP Proxy negotiates the most desirable common codec for both legs.
I a call, the RTP flow can go peer to peer directly or through the SIP Proxy.
If the SIP Proxy can't establish a common codec, and has the capability can TRANSCODE, that is allow a different codec for each leg.
Is important to be able to prioritize the codecs because they are designed for very different scenarios, the G711 for standard PSTN communication, 64KBps, and the ARM and GSM for wireless data, high latency, high packet losses, jitter, etc, etc.