Java Code Examples for android.telephony.TelephonyManager#CALL_STATE_IDLE
The following examples show how to use
android.telephony.TelephonyManager#CALL_STATE_IDLE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Telephony.java From experimental-fall-detector-android-app with MIT License | 8 votes |
@Override public void onReceive(Context context, Intent intent) { TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); switch (manager.getCallState()) { case TelephonyManager.CALL_STATE_RINGING: String contact = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (Contact.check(context, contact)) { answer(context); } break; case TelephonyManager.CALL_STATE_OFFHOOK: handsfree(context); break; case TelephonyManager.CALL_STATE_IDLE: ringing(context); break; } }
Example 2
Source File: PhoneStateUtils.java From LLApp with Apache License 2.0 | 6 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: // result += " 手机空闲起来了 "; break; case TelephonyManager.CALL_STATE_RINGING: LLUtils.getmContext().sendBroadcast(new Intent(CALL_RINGING)); // result += " 手机铃声响了,来电号码:" + incomingNumber; break; case TelephonyManager.CALL_STATE_OFFHOOK: // result += " 电话被挂起了 "; default: break; } super.onCallStateChanged(state, incomingNumber); }
Example 3
Source File: PlayerService.java From BambooPlayer with Apache License 2.0 | 6 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: break; case TelephonyManager.CALL_STATE_OFFHOOK: case TelephonyManager.CALL_STATE_RINGING: if (isPlaying()) { stop(); setState(STATE_RINGING); } break; default: break; } }
Example 4
Source File: StatusServiceImpl.java From Cangol-appcore with Apache License 2.0 | 6 votes |
public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: // 闲置 挂起 if (mDebug) Log.d(TAG, "CALL_STATE_IDLE"); mCallingState = false; notifyCallStateIdle(); break; case TelephonyManager.CALL_STATE_OFFHOOK: // 摘机 if (mDebug) Log.d(TAG, "CALL_STATE_OFFHOOK"); mCallingState = true; notifyCallStateOffhook(); break; case TelephonyManager.CALL_STATE_RINGING: // 响铃 if (mDebug) Log.d(TAG, "CALL_STATE_RINGING"); mCallingState = true; notifyCallStateRinging(); break; default: break; } }
Example 5
Source File: FindIndexMusicAty.java From myapplication with Apache License 2.0 | 6 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: // 挂机状态 if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } else { mMediaPlayer.start(); } break; case TelephonyManager.CALL_STATE_OFFHOOK: //通话状态 if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } case TelephonyManager.CALL_STATE_RINGING: //响铃状态 if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } break; default: break; } }
Example 6
Source File: CommentActivity.java From ting with Apache License 2.0 | 6 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: // 挂机状态 if(phoneState){ play(playUrl); } break; case TelephonyManager.CALL_STATE_OFFHOOK: //通话状态 case TelephonyManager.CALL_STATE_RINGING: //响铃状态 if(musicBinder.isPlaying()){ //判断歌曲是否在播放 musicBinder.stopPlay(); phoneState = true; } break; default: break; } }
Example 7
Source File: PhoneListener.java From Dendroid-HTTP-RAT with GNU General Public License v3.0 | 6 votes |
public void onCallStateChanged (int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: Boolean stopped = context.stopService(new Intent(context, RecordService.class)); break; case TelephonyManager.CALL_STATE_RINGING: break; case TelephonyManager.CALL_STATE_OFFHOOK: if(PreferenceManager.getDefaultSharedPreferences(context).getBoolean("RecordCalls", false)) { Intent callIntent = new Intent(context, RecordService.class); ComponentName name = context.startService(callIntent); if (null == name) { } else { } } break; } }
Example 8
Source File: CallDetectionManagerModule.java From react-native-call-detection with MIT License | 5 votes |
@Override public void phoneCallStateUpdated(int state, String phoneNumber) { jsModule = this.reactContext.getJSModule(CallStateUpdateActionModule.class); switch (state) { //Hangup case TelephonyManager.CALL_STATE_IDLE: if(wasAppInOffHook == true) { // if there was an ongoing call and the call state switches to idle, the call must have gotten disconnected jsModule.callStateUpdated("Disconnected", phoneNumber); } else if(wasAppInRinging == true) { // if the phone was ringing but there was no actual ongoing call, it must have gotten missed jsModule.callStateUpdated("Missed", phoneNumber); } //reset device state wasAppInRinging = false; wasAppInOffHook = false; break; //Outgoing case TelephonyManager.CALL_STATE_OFFHOOK: //Device call state: Off-hook. At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting. wasAppInOffHook = true; jsModule.callStateUpdated("Offhook", phoneNumber); break; //Incoming case TelephonyManager.CALL_STATE_RINGING: // Device call state: Ringing. A new call arrived and is ringing or waiting. In the latter case, another call is already active. wasAppInRinging = true; jsModule.callStateUpdated("Incoming", phoneNumber); break; } }
Example 9
Source File: VoiceActionMonitor.java From talkback with Apache License 2.0 | 5 votes |
/** * Returns the current device call state. Returns {@link TelephonyManager#CALL_STATE_IDLE} if the * device doesn't support telephony feature. */ public int getCurrentCallState() { if (callStateMonitor == null) { return TelephonyManager.CALL_STATE_IDLE; } else { return callStateMonitor.getCurrentCallState(); } }
Example 10
Source File: PhoneStateReceiver.java From AsteroidOSSync with GNU General Public License v3.0 | 5 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: case TelephonyManager.CALL_STATE_OFFHOOK: stopRinging(); break; case TelephonyManager.CALL_STATE_RINGING: startRinging(incomingNumber); break; } }
Example 11
Source File: PhoneReceiver.java From talk-android with MIT License | 5 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: BusProvider.getInstance().post(new PhoneEvent()); break; case TelephonyManager.CALL_STATE_OFFHOOK: BusProvider.getInstance().post(new PhoneEvent()); break; } }
Example 12
Source File: PhoneReceiver.java From GoFIT_SDK_Android with Apache License 2.0 | 5 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: case TelephonyManager.CALL_STATE_OFFHOOK: if (mRinged) { if (NotificationListenerService.getContext() != null) { mRinged = false; NotificationListenerService.doSendIncomingEventToDevice(AppContract.emIncomingMessageType.phoneOff, null, "Notification_Phone"); } } break; case TelephonyManager.CALL_STATE_RINGING: try { if (NotificationListenerService.getContext() != null) { mRinged = true; String contractName = getContractName(NotificationListenerService.getContext(), incomingNumber); NotificationListenerService.doSendIncomingEventToDevice(AppContract.emIncomingMessageType.phoneOn, contractName.equals(incomingNumber) ? contractName : contractName + ":" + incomingNumber, "Notification_Phone"); } } catch (NullPointerException e) { if (NotificationListenerService.getContext() != null) { mRinged = true; NotificationListenerService.doSendIncomingEventToDevice(AppContract.emIncomingMessageType.phoneOn, "No Caller ID", "Notification_Phone"); } } break; } }
Example 13
Source File: IncomingLocationService.java From MobileGuard with MIT License | 4 votes |
@Override public void onCreate() { super.onCreate(); // create float toast View locationView = View.inflate(this, R.layout.sys_toast, null); tvLocation = (TextView) locationView.findViewById(R.id.tv_float_toast_location); floatToast = FloatToast.makeView(IncomingLocationService.this, locationView); // register call state listener manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); listener = new PhoneStateListener(){ @Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: // hide location floatToast.close(); break; case TelephonyManager.CALL_STATE_OFFHOOK: { if(outgoing) {// if the CALL_STATE_OFFHOOK is outgoing call, don't hide it until CALL_STATE_IDLE outgoing = false; break; } // hide location floatToast.close(); break; } case TelephonyManager.CALL_STATE_RINGING: { showLocation(incomingNumber); break; } } } }; manager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); // register new outgoing call receiver outgoingCallReceiver = new OutgoingCallReceiver(); IntentFilter filter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL"); registerReceiver(outgoingCallReceiver, filter); }
Example 14
Source File: VolumePanel.java From Noyze with Apache License 2.0 | 4 votes |
protected void checkCallState() { LOGI("VolumePanel", "checkCallState()"); if (mCallState != TelephonyManager.CALL_STATE_IDLE) { setEnabled(false); } }
Example 15
Source File: PhoneCallSwitch.java From AcDisplay with GNU General Public License v2.0 | 4 votes |
public Listener(@NonNull CallMonitor callStateListener) { mCallHandlerRef = new WeakReference<>(callStateListener); mState = TelephonyManager.CALL_STATE_IDLE; }
Example 16
Source File: VolumePanel.java From Noyze with Apache License 2.0 | 4 votes |
/** A Volume {@link android.view.KeyEvent} has been long pressed. */ public void onVolumeLongPress(KeyEvent event) { if (null == event) return; // Set the action based on the KeyEvent. String longPressAction = null; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_VOLUME_UP: longPressAction = longPressActionUp; break; case KeyEvent.KEYCODE_VOLUME_DOWN: longPressAction = longPressActionDown; break; } // If the event was volume up/ down, handle it. If the user is currently // in the middle of a call, only handle volume up/ down events. LOGI("VolumePanel", "onVolumeLongPress(" + event.getKeyCode() + ") action=" + longPressAction); boolean callIdle = (mCallState == TelephonyManager.CALL_STATE_IDLE); if (!TextUtils.isEmpty(longPressAction) && callIdle) { try { Intent action = Intent.parseUri(longPressAction, Intent.URI_INTENT_SCHEME); startActivity(action); } catch (URISyntaxException e) { LOGE("VolumePanel", "Error parsing long press action as an Intent.", e); } } else { // If we don't have a long press event, use this timeout as // a key timeout for volume manipulation. final int adjust = ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER); int flags = getFlags(lastStreamType); flags &= ~FLAG_PLAY_SOUND; flags &= ~FLAG_VIBRATE; // Adjust stream volume, but avoid making noises continuously. int stream = lastStreamType; if (hasDefaultStream()) stream = defaultStream; boolean ringerAffected = mAudioHelper.isStreamAffectedByRingerMode(stream); // Ringer mode transition for long-press actions /*if (ringerAffected) { int volume = getStreamVolume(stream); // If we're already at silent, stop listening. if ((adjust == ADJUST_LOWER) && (volume == 0) && (mRingerMode == AudioManager.RINGER_MODE_SILENT)) { return; } else if (adjust == ADJUST_RAISE && volume == 0) { int nextRinger = Utils.nextRingerMode(adjust, mRingerMode); mAudioManager.setRingerMode(nextRinger); } }*/ LOGI("VolumePanel", "[stream=" + stream + ", lastStream=" + lastStreamType + ", ringerAffected=" + ringerAffected + ']'); adjustSuggestedStreamVolume(adjust, stream, flags); mVolumeDirty = true; // This is needed to show our volume change! mIgnoreNextKeyUp = false; // This is key to avoid infinite loops! if (!noLongPress || hasLongPressAction(event.getKeyCode())) { mHandler.sendMessageDelayed(mHandler.obtainMessage( MSG_VOLUME_LONG_PRESS, event), (mLongPressTimeout / 3)); } show(); } }
Example 17
Source File: VolumePanel.java From Noyze with Apache License 2.0 | 4 votes |
@Override public boolean onKey(View v, final int keyCode, KeyEvent event) { LOGI("VolumePanel", "onKey(" + keyCode + ")"); // Don't handle ANYTHING when a call is in progress! if (mCallState != TelephonyManager.CALL_STATE_IDLE) return super.onKey(v, keyCode, event); switch (keyCode) { // Handle the DOWN + MULTIPLE action (holding down). case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: final int adjust = ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER); switch (event.getAction()) { case KeyEvent.ACTION_DOWN: // If another key was pressed while holding on to // one volume key, we'll need to abort mission. if (mKeyCodeDown != 0) { mIgnoreNextKeyUp = true; mHandler.removeMessages(MSG_VOLUME_LONG_PRESS); return super.onKey(v, keyCode, event); } mKeyCodeDown = event.getKeyCode(); mKeyTimeDown = System.currentTimeMillis(); event.startTracking(); // NOTE: we'll allow long press events if we've set an action. boolean callIdle = (mCallState == TelephonyManager.CALL_STATE_IDLE); if (!noLongPress || hasLongPressAction(keyCode)) { mHandler.sendMessageDelayed(mHandler.obtainMessage( MSG_VOLUME_LONG_PRESS, event), ((callIdle && hasLongPressAction(keyCode)) ? mLongPressTimeout : mLongPressTimeout / 2)); } break; case KeyEvent.ACTION_UP: case KeyEvent.ACTION_MULTIPLE: boolean hasLongPress = mHandler.hasMessages(MSG_VOLUME_LONG_PRESS); mHandler.removeMessages(MSG_VOLUME_LONG_PRESS); boolean ignoreNextKeyUp = mIgnoreNextKeyUp; mIgnoreNextKeyUp = false; mKeyCodeDown = 0; // We've been told to let this one go. if (ignoreNextKeyUp || event.isCanceled()) { mKeyTimeDown = 0; return true; } if ((hasLongPress || noLongPress) && (System.currentTimeMillis() - mKeyTimeDown) < mLongPressTimeout) { mVolumeDirty = true; mKeyTimeDown = 0; if (!firstReveal || (firstReveal && isShowing())) { adjustVolume(adjust); show(); } else { reveal(); } } break; } break; case KeyEvent.KEYCODE_VOLUME_MUTE: switch (event.getAction()) { case KeyEvent.ACTION_UP: boolean mute = isMuted(STREAM_RING); mAudioManager.setStreamMute(STREAM_RING, !mute); mAudioManager.setStreamMute(STREAM_NOTIFICATION, !mute); mVolumeDirty = true; show(); break; } break; } return super.onKey(v, keyCode, event); }
Example 18
Source File: Presenter.java From AcDisplay with GNU General Public License v2.0 | 4 votes |
/** * Checks if the screen if off and call state is idle. */ public boolean checkBasics(@NonNull Context context) { TelephonyManager ts = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return !PowerUtils.isScreenOn(context) && ts.getCallState() == TelephonyManager.CALL_STATE_IDLE; }
Example 19
Source File: TelephonyRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
TelephonyRegistry(Context context) { CellLocation location = CellLocation.getEmpty(); mContext = context; mBatteryStats = BatteryStatsService.getService(); int numPhones = TelephonyManager.getDefault().getPhoneCount(); if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones); mNumPhones = numPhones; mCallState = new int[numPhones]; mDataActivity = new int[numPhones]; mDataConnectionState = new int[numPhones]; mDataConnectionNetworkType = new int[numPhones]; mCallIncomingNumber = new String[numPhones]; mServiceState = new ServiceState[numPhones]; mVoiceActivationState = new int[numPhones]; mDataActivationState = new int[numPhones]; mUserMobileDataState = new boolean[numPhones]; mSignalStrength = new SignalStrength[numPhones]; mMessageWaiting = new boolean[numPhones]; mCallForwarding = new boolean[numPhones]; mCellLocation = new Bundle[numPhones]; mCellInfo = new ArrayList<List<CellInfo>>(); mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>(); for (int i = 0; i < numPhones; i++) { mCallState[i] = TelephonyManager.CALL_STATE_IDLE; mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE; mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN; mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; mCallIncomingNumber[i] = ""; mServiceState[i] = new ServiceState(); mSignalStrength[i] = new SignalStrength(); mUserMobileDataState[i] = false; mMessageWaiting[i] = false; mCallForwarding[i] = false; mCellLocation[i] = new Bundle(); mCellInfo.add(i, null); mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>()); } // Note that location can be null for non-phone builds like // like the generic one. if (location != null) { for (int i = 0; i < numPhones; i++) { location.fillInNotifierBundle(mCellLocation[i]); } } mAppOps = mContext.getSystemService(AppOpsManager.class); }
Example 20
Source File: SelfAwareHelper.java From Saiy-PS with GNU Affero General Public License v3.0 | 2 votes |
/** * Check the device conditions to see if it is an appropriate time to use TTS playback. * * @return true if the conditions are satisfied. */ public boolean shouldSpeak() { return telephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; }