Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to know the call state in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 467
    Comment on it

    Android provide us the facility to know the call state. Android gives this feature by providing Telephonymanager class. We need to implement PhoneStateListener interface that has one method onCallStateChanged().


    Below is the example.

    public class PhoneStateActivity extends Activity {   
    
    
    Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_phone_state); TelephonyManager myTM = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); PhoneStateListener phoneStateListener= new PhoneStateListener() { public void onCallStateChanged(int state, String incomingNumber) { if(state==TelephonyManager.CALL_STATE_RINGING){ Toast.makeText(PhoneStateActivity.this,Hey, receive your call. Phone is ringing.", Toast.LENGTH_LONG).show(); } if(state==TelephonyManager.CALL_STATE_OFFHOOK){ Toast.makeText(PhoneStateActivity.this,"You are in a call. ", Toast.LENGH_LONG).show(); } if(state==TelephonyManager.CALL_STATE_IDLE){ Toast.makeText(PhoneStateActivity.thisYou are in idle state ", Toast.LENGTH_LONG).show(); } } }; myTM.listen(phoneStateListener,PhoneStateListener.LISTEN_CALL_STATE); }

    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: