Java Code Examples for android.telephony.TelephonyManager#getCallState()
The following examples show how to use
android.telephony.TelephonyManager#getCallState() .
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: experimental-fall-detector-android-app File: Telephony.java License: MIT License | 6 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 Project: Linphone4Android File: LinphoneManager.java License: GNU General Public License v3.0 | 5 votes |
public synchronized static final LinphoneManager createAndStart(Context c) { if (instance != null) throw new RuntimeException("Linphone Manager is already initialized"); instance = new LinphoneManager(c); instance.startLibLinphone(c); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE; setGsmIdle(gsmIdle); return instance; }
Example 3
Source Project: Telephoto File: CallReceiver.java License: Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { telephonyManager.listen(new PhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE); if (telephonyManager.getCallState() == TelephonyManager.CALL_STATE_RINGING) { String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); String name = FabricUtils.getNameByPhone(context, phoneNumber); if (senderService != null) { senderService.sendMessageToAll(String.format(context.getString(R.string.incoming_call), phoneNumber, name)); } } } }
Example 4
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 5
Source Project: batteryhub File: Phone.java License: Apache License 2.0 | 5 votes |
public static String getCallState(Context context) { TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int callState = telManager.getCallState(); switch (callState) { case TelephonyManager.CALL_STATE_OFFHOOK: return CALL_STATE_OFFHOOK; case TelephonyManager.CALL_STATE_RINGING: return CALL_STATE_RINGING; default: return CALL_STATE_IDLE; } }
Example 6
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 7
Source Project: Noyze File: VolumePanel.java License: Apache License 2.0 | 5 votes |
public VolumePanel(PopupWindowManager manager) { super(manager); Context context = manager.getContext(); app = (NoyzeApp) context.getApplicationContext(); mStreamControls = new SparseArray<StreamControl>(StreamResources.STREAMS.length); mHandler = new VolumeMediaHandler(context.getMainLooper()); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mVolumeManager = new VolumeManager(mAudioManager); mAudioHelper = AudioHelper.getHelper(context, mAudioManager); // mAudioFlingerProxy = new AudioFlingerProxy(); mAudioHelper.setHandler(mHandler); mLongPressTimeout = ViewConfiguration.getLongPressTimeout(); if (MediaProviderDelegate.IS_V18) mMediaProviderDelegate = MediaProviderDelegate.getDelegate(context); // Register here: be SURE that the handler is not null. if (null == mVolumeMediaReceiver) { mVolumeMediaReceiver = new VolumeMediaReceiver(mHandler); IntentFilter events = Utils.merge(VOLUME_MUSIC_EVENTS(), Constants.MEDIA_ACTION_FILTER()); context.registerReceiver(mVolumeMediaReceiver, events); mVolumeMediaReceiver.setHandler(mHandler); } // Register for events related to the call state. if (null == mCallStateListener) { mCallState = mTelephonyManager.getCallState(); mCallStateListener = new CallStateListener(mHandler); mTelephonyManager.listen(mCallStateListener, PhoneStateListener.LISTEN_CALL_STATE); } initState(); }
Example 8
Source Project: Android-LockScreenSample-DisableHomeButtonKey File: LockscreenService.java License: Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (null != context) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { Intent startLockscreenIntent = new Intent(mContext, LockscreenViewService.class); stopService(startLockscreenIntent); TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); boolean isPhoneIdle = tManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; if (isPhoneIdle) { startLockscreenActivity(); } } } }
Example 9
Source Project: Noyze File: VolumePanel.java License: Apache License 2.0 | 5 votes |
public VolumePanel(PopupWindowManager manager) { super(manager); Context context = manager.getContext(); app = (NoyzeApp) context.getApplicationContext(); mStreamControls = new SparseArray<StreamControl>(StreamResources.STREAMS.length); mHandler = new VolumeMediaHandler(context.getMainLooper()); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); mVolumeManager = new VolumeManager(mAudioManager); mAudioHelper = AudioHelper.getHelper(context, mAudioManager); // mAudioFlingerProxy = new AudioFlingerProxy(); mAudioHelper.setHandler(mHandler); mLongPressTimeout = ViewConfiguration.getLongPressTimeout(); if (MediaProviderDelegate.IS_V18) mMediaProviderDelegate = MediaProviderDelegate.getDelegate(context); // Register here: be SURE that the handler is not null. if (null == mVolumeMediaReceiver) { mVolumeMediaReceiver = new VolumeMediaReceiver(mHandler); IntentFilter events = Utils.merge(VOLUME_MUSIC_EVENTS(), Constants.MEDIA_ACTION_FILTER()); context.registerReceiver(mVolumeMediaReceiver, events); mVolumeMediaReceiver.setHandler(mHandler); } // Register for events related to the call state. if (null == mCallStateListener) { mCallState = mTelephonyManager.getCallState(); mCallStateListener = new CallStateListener(mHandler); mTelephonyManager.listen(mCallStateListener, PhoneStateListener.LISTEN_CALL_STATE); } initState(); }
Example 10
Source Project: bcm-android File: WebRtcCallService.java License: GNU General Public License v3.0 | 4 votes |
private boolean isBusy() { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); return callState.get() != CallState.STATE_IDLE || (telephonyManager != null && telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE); }
Example 11
Source Project: react-native-sip File: PjSipService.java License: GNU General Public License v3.0 | 4 votes |
@Override public int onStartCommand(final Intent intent, int flags, int startId) { if (!mInitialized) { if (intent != null && intent.hasExtra("service")) { mServiceConfiguration = ServiceConfigurationDTO.fromMap((Map) intent.getSerializableExtra("service")); } mWorkerThread = new HandlerThread(getClass().getSimpleName(), Process.THREAD_PRIORITY_FOREGROUND); mWorkerThread.setPriority(Thread.MAX_PRIORITY); mWorkerThread.start(); mHandler = new Handler(mWorkerThread.getLooper()); mEmitter = new PjSipBroadcastEmiter(this); mAudioManager = (AudioManager) getApplicationContext().getSystemService(AUDIO_SERVICE); mPowerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE); mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName()+"-wifi-call-lock"); mWifiLock.setReferenceCounted(false); mTelephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); mGSMIdle = mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; IntentFilter phoneStateFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); registerReceiver(mPhoneStateChangedReceiver, phoneStateFilter); mInitialized = true; job(new Runnable() { @Override public void run() { load(); } }); } if (intent != null) { job(new Runnable() { @Override public void run() { handle(intent); } }); } return START_NOT_STICKY; }
Example 12
Source Project: ForceDoze File: Utils.java License: GNU General Public License v3.0 | 4 votes |
public static boolean isUserInCall(Context context) { TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return manager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK || manager.getCallState() == TelephonyManager.CALL_STATE_RINGING; }
Example 13
Source Project: react-native-pjsip File: PjSipService.java License: GNU General Public License v3.0 | 4 votes |
@Override public int onStartCommand(final Intent intent, int flags, int startId) { if (!mInitialized) { if (intent != null && intent.hasExtra("service")) { mServiceConfiguration = ServiceConfigurationDTO.fromMap((Map) intent.getSerializableExtra("service")); } mWorkerThread = new HandlerThread(getClass().getSimpleName(), Process.THREAD_PRIORITY_FOREGROUND); mWorkerThread.setPriority(Thread.MAX_PRIORITY); mWorkerThread.start(); mHandler = new Handler(mWorkerThread.getLooper()); mEmitter = new PjSipBroadcastEmiter(this); mAudioManager = (AudioManager) getApplicationContext().getSystemService(AUDIO_SERVICE); mPowerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE); mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, this.getPackageName()+"-wifi-call-lock"); mWifiLock.setReferenceCounted(false); mTelephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE); mGSMIdle = mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE; IntentFilter phoneStateFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); registerReceiver(mPhoneStateChangedReceiver, phoneStateFilter); mInitialized = true; job(new Runnable() { @Override public void run() { load(); } }); } if (intent != null) { job(new Runnable() { @Override public void run() { handle(intent); } }); } return START_NOT_STICKY; }
Example 14
Source Project: VCL-Android File: PlaybackService.java License: Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); int state = intent.getIntExtra("state", 0); if( mMediaPlayer == null ) { Log.w(TAG, "Intent received, but VLC is not loaded, skipping."); return; } // skip all headsets events if there is a call TelephonyManager telManager = (TelephonyManager) VLCApplication.getAppContext().getSystemService(Context.TELEPHONY_SERVICE); if (telManager != null && telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) return; /* * Launch the activity if needed */ if (action.startsWith(ACTION_REMOTE_GENERIC) && !mMediaPlayer.isPlaying() && !hasCurrentMedia()) { context.startActivity(getPackageManager().getLaunchIntentForPackage(getPackageName())); } /* * Remote / headset control events */ if (action.equalsIgnoreCase(ACTION_REMOTE_PLAYPAUSE)) { if (mMediaPlayer.isPlaying() && hasCurrentMedia()) pause(); else if (!mMediaPlayer.isPlaying() && hasCurrentMedia()) play(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_PLAY)) { if (!mMediaPlayer.isPlaying() && hasCurrentMedia()) play(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_PAUSE)) { if (mMediaPlayer.isPlaying() && hasCurrentMedia()) pause(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_BACKWARD)) { previous(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_STOP)) { stop(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_FORWARD)) { next(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_LAST_PLAYLIST)) { loadLastPlaylist(); } else if (action.equalsIgnoreCase(ACTION_REMOTE_RESUME_VIDEO)) { switchToVideo(); } else if (action.equalsIgnoreCase(ACTION_WIDGET_INIT)) { updateWidget(); } /* * headset plug events */ if (mDetectHeadset && !mHasHdmiAudio) { if (action.equalsIgnoreCase(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { Log.i(TAG, "Headset Removed."); if (mMediaPlayer.isPlaying() && hasCurrentMedia()) pause(); } else if (action.equalsIgnoreCase(Intent.ACTION_HEADSET_PLUG) && state != 0) { Log.i(TAG, "Headset Inserted."); if (!mMediaPlayer.isPlaying() && hasCurrentMedia()) play(); } } /* * Sleep */ if (action.equalsIgnoreCase(VLCApplication.SLEEP_INTENT)) { stop(); } }
Example 15
Source Project: AcDisplay File: Presenter.java License: 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 16
Source Project: Pi-Locker File: LockerService.java License: GNU General Public License v2.0 | 3 votes |
@Override public void onReceive(Context context, Intent intent) { TelephonyManager ts = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int callState = ts.getCallState(); if (callState == TelephonyManager.CALL_STATE_IDLE) { startActivity(new Intent(LockerService.this, Lock.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } }