TelephonyManager getCallState - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TelephonyManager getCallState method.

This code example shows how to use the following methods:getCallState
	 */ 
	private static boolean isInCall(Context context)
	{ 
		if (sInCall == -1) {
			TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
			sInCall = (byte)(manager.getCallState() == TelephonyManager.CALL_STATE_IDLE ? 0 : 1);
		} 
		return sInCall == 1;
	} 
 
	/** 
	 * Set the cached value for whether the phone is in a call. 
	 * 
	 * @param value True if in a call, false otherwise. 
	 */ 
	public static void setInCall(boolean value)
	{ 
		sInCall = value ? 1 : 0;
	} 
 
7
CodeRank
This code example shows how to use the following methods:getCallState
        public RockboxTimerTask(RockboxService s, RockboxTimer parent) 
        { 
            super(); 
            timer = parent;
            tm = (TelephonyManager)s.getSystemService(Context.TELEPHONY_SERVICE);
            last_state = tm.getCallState();
        } 
 
        @Override 
        public void run()  
        { 
            timerTask(); 
            int state = tm.getCallState();
            if (state != last_state)
            { 
                switch (state) 
                { 
                    case TelephonyManager.CALL_STATE_IDLE:
                        postCallHungUp(); 
                        break; 
6
CodeRank
This code example shows how to use the following methods:getCallState, getCellLocation, getDeviceId, getDeviceSoftwareVersion, getNetworkOperator
		TelephonyManager telephonyManager =
		(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
		 
		 
		/** Network Information **/ 
		String nomOperateurReseau = telephonyManager.getNetworkOperatorName();
		if (nomOperateurReseau != null)
		{ 
			Log.v("Network Operator Name", nomOperateurReseau);
		} 
		 
		/** CellID Lookup **/	 
		GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
		try { 
		int cid = location.getCid();
		int lac = location.getLac();
		if (Integer.toString(cid) != null && Integer.toString(lac) != null) {
			Log.v("CellID Information", Integer.toString(cid));
			Log.v("Location Area Code Information", Integer.toString(lac));
		} 

6
CodeRank
This code example shows how to use the following methods:getCallState
     * Sets the Volume level in sensible range. Handles special case of someone is calling or if on call. 
     * @param context 
     */ 
    private void setReasonableVolume(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        int callState = tm.getCallState();
        if (callState == TelephonyManager.CALL_STATE_OFFHOOK) {
            Log.v(TAG, "Customer on the phone, let's change volume");
            player.setVolume(VOLUME_OFF, VOLUME_OFF);
        } else if (callState == TelephonyManager.CALL_STATE_RINGING) {
            Log.v(TAG, "Someone is calling! Let's decrease volume.");
            player.setVolume(RINGING_VOLUME, RINGING_VOLUME);
        } else { 
            player.setVolume(1f, 1f);
        } 
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:getCallState, getLine1Number, getPhoneType, getSimOperator, getSimOperatorName
		info.append("\n");
		return info.toString();
	} 
 
	public String getSimState() {
		switch (mTm.getSimState()) {
		case android.telephony.TelephonyManager.SIM_STATE_UNKNOWN:
			return "未知SIM状态_" 
					+ android.telephony.TelephonyManager.SIM_STATE_UNKNOWN;
		case android.telephony.TelephonyManager.SIM_STATE_ABSENT:
			return "没插SIM卡_" 
					+ android.telephony.TelephonyManager.SIM_STATE_ABSENT;
		case android.telephony.TelephonyManager.SIM_STATE_PIN_REQUIRED:
			return "锁定SIM状态_需要用户的PIN码解锁_" 
					+ android.telephony.TelephonyManager.SIM_STATE_PIN_REQUIRED;
		case android.telephony.TelephonyManager.SIM_STATE_PUK_REQUIRED:
			return "锁定SIM状态_需要用户的PUK码解锁_" 
					+ android.telephony.TelephonyManager.SIM_STATE_PUK_REQUIRED;
		case android.telephony.TelephonyManager.SIM_STATE_NETWORK_LOCKED:
			return "锁定SIM状态_需要网络的PIN码解锁_" 

6
CodeRank
This code example shows how to use the following methods:getCallState
	public void onReceive(Context context, Intent intent)
	{ 
 
		TelephonyManager tm = (TelephonyManager) context
				.getSystemService(Service.TELEPHONY_SERVICE);
		switch (tm.getCallState())
		{ 
			case TelephonyManager.CALL_STATE_RINGING: // ����
				// ���������ĵ绰�� 
				String incomingNumber = intent
						.getStringExtra("incoming_number");
				if ("12345678".equals(incomingNumber))
				{ 
					try 
					{ 
						 
						 
						TelephonyManager telephonyManager = (TelephonyManager) context
								.getSystemService(Service.TELEPHONY_SERVICE);
						Class<TelephonyManager> telephonyManagerClass = TelephonyManager.class;
6
CodeRank
This code example shows how to use the following methods:getCallState
     
    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);
6
CodeRank
This code example shows how to use the following methods:getCallState, listen
		String phoneNumber = intent  
		        .getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); 
        TelephonyManager tm = (TelephonyManager) context  
                .getSystemService(Context.TELEPHONY_SERVICE);
           
        switch (tm.getCallState()) {  
        case TelephonyManager.CALL_STATE_RINGING:  
        	Time time = new Time();
        	time.setToNow();
//            Toast.makeText(context, "hour:" + time.hour+"minute:"+time.minute,   
//                    Toast.LENGTH_SHORT).show(); 
        	if (time.hour==START_HOUR && time.minute > START_MIN && time.weekDay != 6 && time.weekDay != 0){
//        	if (true){ 
                SharedPreferences mPhonePreference = context.getSharedPreferences("block_phone",
        				Context.MODE_PRIVATE);
        		String number = mPhonePreference.getString("PhoneNumber", "15921551027");
                Toast.makeText(context, "Ring:" + phoneNumber + " get:"+number,  
                        Toast.LENGTH_SHORT).show();
                PhoneCallStateListener customPhoneListener = new PhoneCallStateListener(context);
                tm.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

5
CodeRank
This code example shows how to use the following methods:getCallState
		} 
	} 
 
	static int phoneState(Object getContext) {
		telephonyManager = (TelephonyManager) getContext;
		if (telephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
			return 1; 
		} 
		if (telephonyManager.getCallState() == TelephonyManager.CALL_STATE_RINGING) {
			return 2; 
		} 
		if (telephonyManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK) {
			return 3; 
		} 
		return 0; 
	} 
	 
} 
5
CodeRank
This code example shows how to use the following methods:getCallState
            mVibrationStartupLevel = sp.getInt(PreferenceKeys.Ringer.VIBRATOR_STARTUP_LEVEL, maxVolume);;
        } 
    } 
 
    private boolean isRinging() { 
        return mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_RINGING;
    } 
     
    @Override 
    protected boolean shouldStop() { 
        return !isRinging(); 
    } 
     
    private boolean isGlobalVibrateOn() { 
        AudioManager audioManager = (AudioManager) this.getSystemService(AUDIO_SERVICE);
        return audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER) == AudioManager.VIBRATE_SETTING_ON;
        //return audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER); 
    } 
     
    private void setVibration(boolean on) {
6
CodeRank

Related TelephonyManager getCallState Questions & Answers:

getCallState Method Overview
Returns a constant indicating the call state (cellular) on the device.
See Code Examples for other Android TelephonyManager Methods: