2010-10-07 4 views
0

j'ai récepteur de radiodiffusion d'appel entrant et de l'état de téléphone classe auditeur, comment bloquer ou rejeter un appel entrant et la notification sonneriede blocage des appels entrants - Android

BroadcastReceiver

public class PhoneCallReceiver extends BroadcastReceiver{ 

    private static final String TAG = "Phone call"; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
      Log.v(TAG, "Receving...."); 
      TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
      SamplePhoneStateListener customPhoneListener = new SamplePhoneStateListener(); 
      telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);    

    } 
} 

Téléphone Listener

public class SamplePhoneStateListener extends PhoneStateListener { 

    private static final String TAG = "Phone Listner"; 

@Override 
public void onCallStateChanged(int state, String incomingNumber) { 
     Log.v(TAG, "Current State is - "+state); 
     Log.v(TAG, incomingNumber); 
     switch(state){ 
       case TelephonyManager.CALL_STATE_RINGING: 
         Log.d(TAG, "Phone Ringigg"); 
         break; 
     }  
    super.onCallStateChanged(state, incomingNumber); 
} 


} 

Répondre

1

assurez-vous que vous avez la permission android.permission.READ_PHONE_STATE mis en place.

0

Pour bloquer un appel, vous devez utiliser les réflexions Java et accéder au fichier caché du package android.telephony. ce fichier (ITelephony.java) a une fonction appelée endcall() qui utilise des permissions. cela n'est pas conseillé par google team car la réception et la fin des appels d'une manière programmatique est une atteinte à la vie privée de l'utilisateur.

Questions connexes