Pergunta

im usando uma chamada de telefone do ouvinte na minha atividade, mas após terminar a atividade , depois de o usuário fazer uma chamada, o meu telefonema ouvinte não está morto e brigue até a atividade novamente !!por favor me ajude.

phoneListener = new PhoneCallListener();
telephonyManager = (TelephonyManager) 
            TransferActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,  PhoneStateListener.LISTEN_CALL_STATE);

PhoneCallListener classe :

private class PhoneCallListener extends PhoneStateListener {
    boolean isPhoneCalling = false;
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        if (TelephonyManager.CALL_STATE_RINGING == state) {
        }
        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            isPhoneCalling = true;
        }
        if (TelephonyManager.CALL_STATE_IDLE == state) {
            if (isPhoneCalling) {
                isPhoneCalling = false;
                    Intent intent = getIntent();
                    startActivity(intent);
                }
            }
        }
    }
}
Foi útil?

Solução

A documentação diz:

Para anular o registo de um ouvinte, passar o objeto de escuta e definir os eventos argumento para PhoneStateListener#LISTEN_NONE (0)

Aqui está o link para o docs.

Outras dicas

Você tentar definir o Ouvinte como null,

telephonyManager.listen(null,  PhoneStateListener.LISTEN_NONE);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top