Java Code Examples for android.telephony.TelephonyManager#getCallState()

The following examples show how to use android.telephony.TelephonyManager#getCallState() . 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 vote down vote up
@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: LinphoneManager.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
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 File: CallReceiver.java    From Telephoto with Apache License 2.0 5 votes vote down vote up
@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 File: ModPower.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
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 File: Phone.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
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 File: HostPhoneProfile.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
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 File: VolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
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 File: LockscreenService.java    From Android-LockScreenSample-DisableHomeButtonKey with Apache License 2.0 5 votes vote down vote up
@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 File: VolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
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 File: WebRtcCallService.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
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 File: PjSipService.java    From react-native-sip with GNU General Public License v3.0 4 votes vote down vote up
@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 File: Utils.java    From ForceDoze with GNU General Public License v3.0 4 votes vote down vote up
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 File: PjSipService.java    From react-native-pjsip with GNU General Public License v3.0 4 votes vote down vote up
@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 File: PlaybackService.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@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 File: Presenter.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 File: LockerService.java    From Pi-Locker with GNU General Public License v2.0 3 votes vote down vote up
@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));

	}

}