Java Code Examples for android.telephony.TelephonyManager#CALL_STATE_RINGING
The following examples show how to use
android.telephony.TelephonyManager#CALL_STATE_RINGING .
These examples are extracted from open source projects.
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 Project: Dendroid-HTTP-RAT File: PhoneListener.java License: 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 2
Source Project: always-on-amoled File: PhonecallReceiver.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { //We listen to two intents. The new outgoing call only tells us of an outgoing call. We use it to get the number. if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) { savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER"); } else { String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE); String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER); int state = 0; if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) { state = TelephonyManager.CALL_STATE_IDLE; } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { state = TelephonyManager.CALL_STATE_OFFHOOK; } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) { state = TelephonyManager.CALL_STATE_RINGING; } onCallStateChanged(context, state, number); } }
Example 3
Source Project: dcs-sdk-java File: MediaPlayerImpl.java License: Apache License 2.0 | 6 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { // 电话挂断 case TelephonyManager.CALL_STATE_IDLE: resume(); break; // 等待接电话 case TelephonyManager.CALL_STATE_RINGING: pause(); break; // 通话中 case TelephonyManager.CALL_STATE_OFFHOOK: break; default: break; } }
Example 4
Source Project: MainScreenShow File: PhoneReceiver.java License: GNU General Public License v2.0 | 6 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { // TODO Auto-generated method stub //state 当前状态 incomingNumber,貌似没有去电的API super.onCallStateChanged(state, incomingNumber); Intent it = new Intent(); switch(state){ case TelephonyManager.CALL_STATE_IDLE: it.setAction("com.jiusg.mainscreenshow"); it.putExtra("msg", "call_stop"); context.sendBroadcast(it); break; case TelephonyManager.CALL_STATE_OFFHOOK: it.setAction("com.jiusg.mainscreenshow"); it.putExtra("msg", "call_start"); context.sendBroadcast(it); break; case TelephonyManager.CALL_STATE_RINGING: // System.out.println("响铃:来电号码"+incomingNumber); it.setAction("com.jiusg.mainscreenshow"); it.putExtra("msg", "call_ring"); context.sendBroadcast(it); //输出来电号码 break; } }
Example 5
Source Project: dingtalk-sms File: call_receiver.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void onCallStateChanged(int state, String incomingNumber) { if (lastState == TelephonyManager.CALL_STATE_RINGING && state == TelephonyManager.CALL_STATE_IDLE) { when_miss_call(); } lastState = state; }
Example 6
Source Project: VCL-Android File: PlaybackService.java License: Apache License 2.0 | 5 votes |
private void initPhoneListener() { mPhoneStateListener = new PhoneStateListener(){ @Override public void onCallStateChanged(int state, String incomingNumber) { if (!mMediaPlayer.isPlaying() || !hasCurrentMedia()) return; if (state == TelephonyManager.CALL_STATE_RINGING || state == TelephonyManager.CALL_STATE_OFFHOOK) pause(); else if (state == TelephonyManager.CALL_STATE_IDLE) play(); } }; }
Example 7
Source Project: YouTube-In-Background File: BackgroundAudioService.java License: MIT License | 5 votes |
private void initPhoneCallListener() { PhoneStateListener phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { //Incoming call: Pause music pauseVideo(); updateAction(ACTION_PLAY); } else if (state == TelephonyManager.CALL_STATE_IDLE) { //Not in call: Play music resumeVideo(); updateAction(ACTION_PAUSE); } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) { //A call is dialing, active or on hold } super.onCallStateChanged(state, incomingNumber); } }; TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mgr != null) { mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } }
Example 8
Source Project: QuranAndroid File: AudioManager.java License: GNU General Public License v3.0 | 5 votes |
/** * Listener to check incoming call */ private void initPhoneListener() { final PhoneStateListener phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { pauseMedia(); } else if (state == TelephonyManager.CALL_STATE_IDLE) { isInCall = false; if (isFirstStart == false) { if (Build.VERSION.SDK_INT >= 17.0) { bigNotification = true; largeMediaPlayer = LargeMediaPlayer.getInstance(context); } else { bigNotification = false; smallMediaPlayer = SmallMediaPlayer.getInstance(context); } resumeMedia(); } isFirstStart = false; } super.onCallStateChanged(state, incomingNumber); } }; telephoneManger = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephoneManger != null) { telephoneManger.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } }
Example 9
Source Project: talkback File: CallStateMonitor.java License: Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (!TalkBackService.isServiceActive()) { LogUtils.w(TAG, "Service not initialized during " + "broadcast."); return; } int oldState = lastCallState; int newState; final String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) { newState = TelephonyManager.CALL_STATE_IDLE; } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) { newState = TelephonyManager.CALL_STATE_OFFHOOK; } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { newState = TelephonyManager.CALL_STATE_RINGING; } else { return; } if (newState != oldState) { LogUtils.v( TAG, "Call state changed: %s -> %s", callStateToString(lastCallState), callStateToString(newState)); lastCallState = newState; for (CallStateChangedListener listener : callStateChangedListeners) { listener.onCallStateChanged(oldState, newState); } } }
Example 10
Source Project: react-native-audio-streaming File: PhoneListener.java License: MIT License | 5 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { Intent restart; switch (state) { case TelephonyManager.CALL_STATE_IDLE: //CALL_STATE_IDLE; //restart = new Intent(this.module.getReactApplicationContextModule(), this.module.getClassActivity()); //restart.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //this.module.getReactApplicationContextModule().startActivity(restart); break; case TelephonyManager.CALL_STATE_OFFHOOK: //CALL_STATE_OFFHOOK; //restart = new Intent(this.module.getReactApplicationContextModule(), this.module.getClassActivity()); //restart.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //this.module.getReactApplicationContextModule().startActivity(restart); break; case TelephonyManager.CALL_STATE_RINGING: //CALL_STATE_RINGING if (this.module.getSignal().isPlaying) { this.module.stopOncall(); } break; default: break; } super.onCallStateChanged(state, incomingNumber); }
Example 11
Source Project: DeviceConnect-Android File: HostPhoneProfile.java License: MIT License | 5 votes |
private CallState detectCurrentCallState(final TelephonyManager telephonyManager) { int state = telephonyManager.getCallState(); switch (state) { case TelephonyManager.CALL_STATE_IDLE: return CallState.STANDBY; case TelephonyManager.CALL_STATE_RINGING: return CallState.RINGING; case TelephonyManager.CALL_STATE_OFFHOOK: default: return CallState.UNKNOWN; } }
Example 12
Source Project: talk-android File: VideoActivity.java License: MIT License | 5 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_RINGING: videoView.pause(); break; case TelephonyManager.CALL_STATE_OFFHOOK: videoView.pause(); break; case TelephonyManager.CALL_STATE_IDLE: videoView.resume(); break; } }
Example 13
Source Project: PowerSwitch_Android File: IncomingCallReceiver.java License: GNU General Public License v3.0 | 5 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { String callState = "UNKNOWN"; switch (state) { case TelephonyManager.CALL_STATE_IDLE: callState = "IDLE"; break; case TelephonyManager.CALL_STATE_RINGING: // -- check international call or not. if (incomingNumber.startsWith("00")) { Toast.makeText(mContext, "International Call- " + incomingNumber, Toast.LENGTH_LONG).show(); callState = "International - Ringing (" + incomingNumber + ")"; } else { Toast.makeText(mContext, "Local Call - " + incomingNumber, Toast.LENGTH_LONG).show(); callState = "Local - Ringing (" + incomingNumber + ")"; } break; case TelephonyManager.CALL_STATE_OFFHOOK: String dialingNumber = mIntent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); if (dialingNumber.startsWith("00")) { Toast.makeText(mContext, "International - " + dialingNumber, Toast.LENGTH_LONG).show(); callState = "International - Dialing (" + dialingNumber + ")"; } else { Toast.makeText(mContext, "Local Call - " + dialingNumber, Toast.LENGTH_LONG).show(); callState = "Local - Dialing (" + dialingNumber + ")"; } break; } Log.d(">>>Broadcast", "onCallStateChanged " + callState); }
Example 14
Source Project: GravityBox File: ModPower.java License: Apache License 2.0 | 5 votes |
private static boolean isIncomingCall() { try { TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); return (phone.getCallState() == TelephonyManager.CALL_STATE_RINGING); } catch (Throwable t) { XposedBridge.log(t); return false; } }
Example 15
Source Project: Android-Music-Player File: Ui.java License: MIT License | 5 votes |
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); if (state == TelephonyManager.CALL_STATE_RINGING) { String phoneNumber = incomingNumber; } }
Example 16
Source Project: Saiy-PS File: SelfAware.java License: GNU Affero General Public License v3.0 | 5 votes |
@Override public void onCallStateChanged(final int state, final String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_OFFHOOK: if (DEBUG) { MyLog.i(CLS_NAME, "PhoneStateListener: TelephonyManager.CALL_STATE_OFFHOOK"); } interrupt(); break; case TelephonyManager.CALL_STATE_RINGING: if (DEBUG) { MyLog.i(CLS_NAME, "PhoneStateListener: TelephonyManager.CALL_STATE_RINGING: " + incomingNumber); } interrupt(); break; case TelephonyManager.CALL_STATE_IDLE: if (DEBUG) { MyLog.i(CLS_NAME, "PhoneStateListener: TelephonyManager.CALL_STATE_IDLE"); } if (conditions.restartHotword()) { startHotwordDetection(conditions.getBundle()); } conditions.removeInterrupted(params); break; } }
Example 17
Source Project: iGap-Android File: MyPhoneStateListener.java License: GNU Affero General Public License v3.0 | 5 votes |
public void onCallStateChanged(int state, String incomingNumber) { if (lastPhoneState == state || !MusicPlayer.isMusicPlyerEnable) { return; } else { lastPhoneState = state; if (state == TelephonyManager.CALL_STATE_RINGING) { pauseSoundIfPlay(); } else if (state == TelephonyManager.CALL_STATE_IDLE) { if (MusicPlayer.pauseSoundFromCall) { MusicPlayer.pauseSoundFromCall = false; MusicPlayer.playSound(); //if (isBlutoothOn) { // isBlutoothOn = false; // // AudioManager am = (AudioManager) G.context.getSystemService(Context.AUDIO_SERVICE); // am.setBluetoothScoOn(true); //} } } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) { pauseSoundIfPlay(); } } }
Example 18
Source Project: react-native-call-detection File: CallDetectionManagerModule.java License: 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 19
Source Project: talkback File: CallStateMonitor.java License: Apache License 2.0 | 4 votes |
/** * Return {@code true} if there is at least one call ringing/waiting/dialing/active or on hold. */ public boolean isPhoneCallActive() { int currentState = getCurrentCallState(); return currentState == TelephonyManager.CALL_STATE_RINGING || currentState == TelephonyManager.CALL_STATE_OFFHOOK; }
Example 20
Source Project: Android-Music-Player File: musicPlayer.java License: MIT License | 4 votes |
@Override public void onCreate() { TelephonyManager telephonyManager = (TelephonyManager)getSystemService(getBaseContext().TELEPHONY_SERVICE); PhoneStateListener callStateListener = new PhoneStateListener() { public void onCallStateChanged(int state, String incomingNumber) { if(state==TelephonyManager.CALL_STATE_RINGING){ //Toast.makeText(getApplicationContext(),"Phone Is Riging", Toast.LENGTH_LONG).show(); if(handler.mediaplayer.isPlaying()){ byCall = true; handler.mediaplayer.pause(); } } if(state==TelephonyManager.CALL_STATE_OFFHOOK){ //Toast.makeText(getApplicationContext(),"Phone is Currently in A call", Toast.LENGTH_LONG).show(); if(handler.mediaplayer.isPlaying()){ byCall = true; handler.mediaplayer.pause(); } } if(state==TelephonyManager.CALL_STATE_IDLE){ //Toast.makeText(getApplicationContext(),"phone is neither ringing nor in a call", Toast.LENGTH_LONG).show(); if(byCall){ byCall = false; handler.mediaplayer.start(); } } } }; telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE); mSettingsContentObserver = new SettingsContentObserver( new Handler() ); this.getContentResolver().registerContentObserver( android.provider.Settings.System.CONTENT_URI, true, mSettingsContentObserver ); THIS = this; handler = new musicHandler(this); super.onCreate(); //statusBar(); handler.mEvent.addEvent(new EventCall(new int[]{playerEvents.PLAYER_COMPLETE,playerEvents.SONG_CHANGED,playerEvents.PLAYING_FLIP}){ @Override public void onCall(final int eventId) { new Thread(){ @Override public void run() { showNotification(eventId); } }.start(); } }); showNotification(-1); }