I have done a search about how to stop media player when receive a call from phone or Whatsapp
val phoneStateListener: PhoneStateListener = object : PhoneStateListener() { override fun onCallStateChanged(state: Int, incomingNumber: String) { if (state == TelephonyManager.CALL_STATE_RINGING) { //Incoming call: Pause music } else if (state == TelephonyManager.CALL_STATE_IDLE) { //Not in call: Play music } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) { //A call is dialing, active or on hold } super.onCallStateChanged(state, incomingNumber) } } val mgr = getSystemService(TELEPHONY_SERVICE) as TelephonyManager mgr?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
https://stackoverflow.com/questions/67327307/how-to-stop-media-player-when-receive-call-in-kotlin April 30, 2021 at 10:08AM
没有评论:
发表评论