Dans le manifeste, vous devez disposer des autorisations suivantes pour vérifier l'appel sortant:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
et le code du récepteur de radiodiffusion:
public class PhoneStateChecking extends BroadcastReceiver {
boolean hasCallStateRinging = false;
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Intent", intent.toString());
if(intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
Log.e("CAll-STATUS", "out going Call");
}
// Checking for the call status
try {
// TELEPHONY MANAGER class object to register one listner
TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//Create Listner
MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
// Register listener for LISTEN_CALL_STATE
tmgr.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
} catch (Exception e) {
e.printStackTrace();
}
}
private class MyPhoneStateListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
if (hasCallStateRinging)
return;
else {
hasCallStateRinging = true;
Log.e("CAll-STATUS", "CALL_STATE_RINGING");
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if(!hasCallStateRinging){
hasCallStateRinging = true;
Log.e("CAll-STATUS", "CALL_STATE_OFFHOOK");
}
break;
case TelephonyManager.CALL_STATE_IDLE:
if (hasCallStateRinging) {
hasCallStateRinging = false;
Log.e("CAll-STATUS", "CALL_STATE_IDLE");
}
break;
}
}
}
}
J'ai vu des réponses indiquant qu'il n'y a aucun moyen de déterminez si la ligne à l'autre extrémité d'un appel sortant sonne. Je ne le sais pas pour un fait cependant. – nasch