Code example for TelephonyManager

Methods: getCallState

0
     
    private void handleCallStateChanged(Context context, Intent intent)
    { 
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
         
        switch(telephonyManager.getCallState())
        { 
          case TelephonyManager.CALL_STATE_IDLE:
            // Phone stopped ringing 
            VolumeControl.resumeVolume(context);
            break; 
          case TelephonyManager.CALL_STATE_RINGING:
            // Phone is ringing 
            String incomingNumber = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            List<PhoneNumber> contacts = ContactsListPersistence.getContactList(context);
             
            if (contacts.contains(new PhoneNumber(incomingNumber)))
            { 
                VolumeControl.saveVolume(context);
                VolumeControl.maxVolume(context);
            }