[Spirit FM] mikereidis:
I'm impressed you remember.

And it's nice to see I can take 36 hours of public seclusion and answers still flow.

Yeah, after the Xperia P/U/Sola/Go, Sony changed audio to use what I call the "Qualcomm Intents", at least for Xperia T era.

Now they use what I call "Sony New", and I've combined them since they don't seem to interfere and because different Sony Android versions do it differently and it's too hard/fragile to try and determine each:

Mute:

Intent i = new Intent ("qualcomm.intent.action.FM");
i.putExtra ("state", 0);
sendBroadcast (i);

setFmReceiverOn (false);

Speaker:

Intent i = new Intent ("qualcomm.intent.action.FM");
i.putExtra ("state", 1);
sendBroadcast (i);
setForceUse (FOR_MEDIA, FORCE_SPEAKER);

setFmReceiverOn (true);
setSpeakerMediaOn (true);

Headset:

Intent i = new Intent ("qualcomm.intent.action.FM");
i.putExtra ("state", 1);
sendBroadcast (i);
setForceUse (FOR_MEDIA, FORCE_NONE);

setFmReceiverOn (true);
setSpeakerMediaOn (false);

The rest:

/* New Sony:
invoke-virtual {v0, p1}, Landroid/media/AudioManager;->setFmReceiverOn(Z)V
invoke-virtual {v0, v1}, Landroid/media/AudioManager;->setSpeakerMediaOn(Z)V
*/
private void setFmReceiverOn (final boolean state) {
logd ("setFmReceiverOn state: " + state);

//media_info ();
/*
try {
Class<?> audioSystem = Class.forName ("android.media.AudioSystem"); // Use reflection
Method setFmReceiverOn = audioSystem.getMethod ("setFmReceiverOn", boolean.class);
setFmReceiverOn.invoke (audioSystem, state);
logd ("setFmReceiverOn 1a done");
setFmReceiverOn.invoke (AudioManager.class, state);
logd ("setFmReceiverOn 1b done");
}
catch (Exception e) {
loge ("setFmReceiverOn 1 exception: " + e);
}
*/
///*
try {
/*AudioManager myAM = (AudioManager) getSystemService ("audio");//AUDIO_SERVICE);
logd ("media_info myAM: " + myAM);
if (myAM == null)
return;*/

Method setFmReceiverOn = AudioManager.class.getMethod ("setFmReceiverOn", boolean.class);
setFmReceiverOn.invoke (mAM, state);
logd ("setFmReceiverOn done");
}
catch (Exception e) {
loge ("setFmReceiverOn exception: " + e);
}
//*/
/*
try {
Class<?> audioSystem = Class.forName ("android.media.AudioManager");
Method setFmReceiverOn = audioSystem.getMethod ("setFmReceiverOn", boolean.class);
setFmReceiverOn.invoke (audioSystem, state);
logd ("setFmReceiverOn 3 done");
}
catch (Exception e) {
loge ("setFmReceiverOn 3 exception: " + e);
}
*/
return;
}
//am_qualc
private void setSpeakerMediaOn (final boolean state) {
logd ("setSpeakerMediaOn state: " + state);
/*
try {
Class<?> audioSystem = Class.forName ("android.media.AudioSystem"); // Use reflection
Method setSpeakerMediaOn = audioSystem.getMethod ("setSpeakerMediaOn", boolean.class);
setSpeakerMediaOn.invoke (AudioManager.class, state);
logd ("setSpeakerMediaOn 1a done");
setSpeakerMediaOn.invoke (audioSystem, state);
logd ("setSpeakerMediaOn 1b done");
}
catch (Exception e) {
loge ("setSpeakerMediaOn 1 exception: " + e);
}
*/
/*
try {
Method setSpeakerMediaOn = AudioManager.class.getMethod ("setSpeakerMediaOn", boolean.class);
Method setSpeakerMediaOn.invoke (mAM, state);
logd ("setSpeakerMediaOn 2 done");
}
catch (Exception e) {
loge ("setSpeakerMediaOn 2 exception: " + e);
}
*/

try {
Class<?> audioSystem = Class.forName ("android.media.AudioManager");
Method setSpeakerMediaOn = audioSystem.getMethod ("setSpeakerMediaOn", boolean.class);
//setSpeakerMediaOn.invoke (audioSystem, state);
//setSpeakerMediaOn 3 exception: java.lang.IllegalArgumentException: expected receiver of type android.media.AudioManager, but got java.lang.Class<android.media.AudioManager>
/*
AudioManager myAM = (AudioManager) getSystemService ("audio");//AUDIO_SERVICE);
logd ("media_info myAM: " + myAM);
if (myAM == null)
return;*/
//Method setSpeakerMediaOn = myAM.getMethod ("setSpeakerMediaOn", boolean.class);
setSpeakerMediaOn.invoke (mAM, state);

logd ("setSpeakerMediaOn done");
}
catch (Exception e) {
loge ("setSpeakerMediaOn exception: " + e);
}

return;
}

public int setForceUse (final int usage, final int config) { // Called by out_set ()
int ret = -9;
logd ("setForceUse usage: " + usage + " config: " + config);
try {
Class<?> audioSystem = Class.forName ("android.media.AudioSystem"); // Use reflection
Method setForceUse = audioSystem.getMethod ("setForceUse", int.class, int.class);
//Method setForceUse = AudioManager.class.getMethod ("setForceUse", int.class, int.class);
ret = (Integer) setForceUse.invoke (audioSystem, usage, config);
//ret = (Integer) setForceUse.invoke (mAM, usage, config);
logd ("setForceUse ret: " + ret);
}
catch (Exception e) {
loge ("setForceUse exception: " + e);
}
return (ret);
}