Pregunta

I am working on an android app that does audio routing to speaker/wired headset. Given that some audio is playing, is it possible to programmatically detect whether the audio playing is a song (media clip) or if it is voice from an established call, using java?

EDIT: I realized that I can solve my problem easily because, when I receive or make a call, only that voice audio can be heard. Is there any function which determines if I am on a call or not?

¿Fue útil?

Solución

Try this function:

public boolean isOnCall(Context context){
   AudioManager manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
   if(manager.getMode()==AudioManager.MODE_IN_CALL){
       return true;
   }
   else{
       return false;
   }
}

Add permission in manifest, too.

<uses-permission android:name="android.permission.READ_PHONE_STATE" />  

Hope this helps.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top