appel sortant à détecter PhoneStateListener
-
09-10-2019 - |
Question
Je veux détecter appel sortant en application android. En fait, je peux détecter les appels sortants, mais il fonctionne aussi trop entrant et je ne veux pas. J'ai besoin pour travailler uniquement pour les messages sortants. voici mon code ....
boolean ringing = false;
boolean offhook = false;
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
if((!ringing)&& offhook){
///incomming call
}
break;
case TelephonyManager.CALL_STATE_RINGING:
callerPhoneNumber = incomingNumber;
Log.d(TAG, "RINGING");
ringing = true;
offhook = false;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d(TAG, "OFFHOOK");
offhook = true;
ringing = false;
break;
}
La solution
Vous pouvez écrire un récepteur de diffusion pour android.intent.action.NEW_OUTGOING_CALL
.
Voir Exemple de code est disponible
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow