Example usage for android.telephony TelephonyManager CALL_STATE_RINGING

List of usage examples for android.telephony TelephonyManager CALL_STATE_RINGING

Introduction

In this page you can find the example usage for android.telephony TelephonyManager CALL_STATE_RINGING.

Prototype

int CALL_STATE_RINGING

To view the source code for android.telephony TelephonyManager CALL_STATE_RINGING.

Click Source Link

Document

Device call state: Ringing.

Usage

From source file:com.neuron.fantecremote.PhoneIntentReciever.java

public void onCallStateChanged(int state, String incomingNumber) {
    switch (state) {
    case TelephonyManager.CALL_STATE_IDLE:
        //Log.d("DEBUG", "IDLE");
        break;//from   w w w. j  av  a2s .co m
    case TelephonyManager.CALL_STATE_OFFHOOK:
        //Log.d("DEBUG", "OFFHOOK");
        break;
    case TelephonyManager.CALL_STATE_RINGING:
        //Log.d("DEBUG", "RINGING");
        String apiurl = Settings.GetApiUrl(prefs);
        if (apiurl != null && prefs.getBoolean("autopause", true)) {
            new SendCommandTask().execute(apiurl + "CMD_PAUSE");
        }
        break;
    }
}

From source file:com.goftagram.telegram.messenger.MusicPlayerService.java

@Override
public void onCreate() {
    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged);
    try {/*ww w . j a  v  a 2 s  . c  om*/
        phoneStateListener = new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                if (state == TelephonyManager.CALL_STATE_RINGING) {
                    if (MediaController.getInstance()
                            .isPlayingAudio(MediaController.getInstance().getPlayingMessageObject())
                            && !MediaController.getInstance().isAudioPaused()) {
                        MediaController.getInstance()
                                .pauseAudio(MediaController.getInstance().getPlayingMessageObject());
                    }
                } else if (state == TelephonyManager.CALL_STATE_IDLE) {

                } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {

                }
                super.onCallStateChanged(state, incomingNumber);
            }
        };
        TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (mgr != null) {
            mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    super.onCreate();
}

From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java

@Override
public void onCreate() {
    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    NotificationManager.getInstance().addObserver(this, NotificationManager.audioProgressDidChanged);
    NotificationManager.getInstance().addObserver(this, NotificationManager.audioPlayStateChanged);
    try {//from w w  w  .ja  va 2 s.co  m
        phoneStateListener = new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                if (state == TelephonyManager.CALL_STATE_RINGING) {
                    if (MediaController.getInstance()
                            .isPlayingAudio(MediaController.getInstance().getPlayingSongDetail())
                            && !MediaController.getInstance().isAudioPaused()) {
                        MediaController.getInstance()
                                .pauseAudio(MediaController.getInstance().getPlayingSongDetail());
                    }
                } else if (state == TelephonyManager.CALL_STATE_IDLE) {

                } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {

                }
                super.onCallStateChanged(state, incomingNumber);
            }
        };
        TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (mgr != null) {
            mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
        }
    } catch (Exception e) {
        Log.e("tmessages", e.toString());
    }
    super.onCreate();
}

From source file:com.smedic.tubtub.BackgroundAudioService.java

private void initPhoneCallListener() {
    PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override//ww  w. j  a  v a2  s  .c  o  m
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                pauseVideo();
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                resumeVideo();
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
            default:
                break;
            }

            super.onCallStateChanged(state, incomingNumber);
        }
    };

    TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if (mgr != null) {
        mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    }
}

From source file:za.co.neilson.alarm.alert.AlarmAlertActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    window.addFlags(//from  w ww  .j a v a 2s.co  m
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    setContentView(R.layout.alarm_alert);

    Bundle bundle = this.getIntent().getExtras();
    alarm = (Alarm) bundle.getSerializable("alarm");

    sendNotification(this, alarm.getAlarmName(), alarm);

    this.setTitle(alarm.getAlarmName());

    switch (alarm.getDifficulty()) {
    case SUPEREASY:
        mathProblem = new MathProblem(1);
        break;
    case EASY:
        mathProblem = new MathProblem(3);
        break;
    case MEDIUM:
        mathProblem = new MathProblem(4);
        break;
    case HARD:
        mathProblem = new MathProblem(5);
        break;
    }

    answerString = String.valueOf(mathProblem.getAnswer());
    if (answerString.endsWith(".0")) {
        answerString = answerString.substring(0, answerString.length() - 2);
    }

    problemView = (TextView) findViewById(R.id.textView1);
    problemView.setText(mathProblem.toString());

    answerView = (TextView) findViewById(R.id.textView2);
    answerView.setText("= ?");

    ((Button) findViewById(R.id.Button0)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button1)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button2)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button3)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button4)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button5)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button6)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button7)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button8)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button9)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button_clear)).setOnClickListener(this);
    final AlarmAlertActivity foo = this;
    ((Button) findViewById(R.id.Button_alarm_off)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            alarmActive = false; //Toast.makeText(getApplicationContext(),"off",Toast.LENGTH_SHORT).show();
            foo.finish();
        }
    });
    ((Button) findViewById(R.id.Button_decimal)).setOnClickListener(this);
    ((Button) findViewById(R.id.Button_minus)).setOnClickListener(this);

    TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

    PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                Log.d(getClass().getSimpleName(), "Incoming call: " + incomingNumber);
                try {
                    mediaPlayer.pause();
                } catch (IllegalStateException e) {

                }
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                Log.d(getClass().getSimpleName(), "Call State Idle");
                try {
                    mediaPlayer.start();
                } catch (IllegalStateException e) {

                }
                break;
            }
            super.onCallStateChanged(state, incomingNumber);
        }
    };

    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    // Toast.makeText(this, answerString, Toast.LENGTH_LONG).show();

    startAlarm();

}

From source file:com.pandoroid.PandoraRadioService.java

@Override
public void onCreate() {
    m_paused = false;// w ww  . j  a v  a2  s .c  o m
    m_pandora_remote = new PandoraRadio();
    image_downloader = new ImageDownloader();
    m_stations = new ArrayList<Station>();

    connectivity_manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    m_prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    // Register the listener with the telephony manager
    telephonyManager.listen(new PhoneStateListener() {
        boolean pausedForRing = false;

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {

            case TelephonyManager.CALL_STATE_IDLE:
                if (pausedForRing && m_song_playback != null) {
                    if (m_prefs.getBoolean("behave_resumeOnHangup", true)) {
                        if (m_song_playback != null && !m_paused) {
                            m_song_playback.play();
                        }
                    }
                }

                pausedForRing = false;
                break;

            case TelephonyManager.CALL_STATE_OFFHOOK:
            case TelephonyManager.CALL_STATE_RINGING:
                if (m_song_playback != null) {
                    m_song_playback.pause();
                }

                pausedForRing = true;
                break;
            }
        }
    }, PhoneStateListener.LISTEN_CALL_STATE);

    m_music_intent_receiver = new MusicIntentReceiver();
    this.registerReceiver(m_music_intent_receiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
}

From source file:org.durka.hallmonitor.CoreStateManager.java

CoreStateManager(Context context) {
    mAppContext = context;//from  w ww  .java2 s  . c  o m
    mPowerManager = (PowerManager) mAppContext.getSystemService(Context.POWER_SERVICE);
    daPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreStateManager");
    daPartialWakeLock.setReferenceCounted(false);
    globalPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreReceiver");
    globalPartialWakeLock.setReferenceCounted(true);

    preference_all = PreferenceManager.getDefaultSharedPreferences(mAppContext);

    // Enable access to sleep mode
    systemApp = (mAppContext.getApplicationInfo().flags
            & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
    if (systemApp) {
        Log.d(LOG_TAG, "We are a system app.");
    } else {
        Log.d(LOG_TAG, "We are not a system app.");
        preference_all.edit().putBoolean("pref_internal_power_management", false).commit();
    }

    refreshAdminApp();
    refreshRootApp();

    refreshLockMode();
    refreshOsPowerManagement();
    refreshInternalPowerManagement();

    refreshInternalService();

    if (preference_all.getBoolean("pref_proximity", false)) {
        forceCheckCoverState = true;
    }

    hmAppWidgetManager = new HMAppWidgetManager(this);

    if (preference_all.getBoolean("pref_default_widget", false)) {
        int widgetId = preference_all.getInt("default_widget_id", -1);
        if (widgetId == -1) {
            registerWidget("default");
        } else {
            createWidget("default");
        }
    }

    if (preference_all.getBoolean("pref_media_widget", false)) {
        audioManager = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);

        int widgetId = preference_all.getInt("media_widget_id", -1);
        if (widgetId == -1) {
            registerWidget("media");
        } else {
            createWidget("media");
        }
    }

    this.hardwareAccelerated = preference_all.getBoolean("pref_hardwareAccelerated", false);

    // we might have missed a phone-state revelation
    phone_ringing = ((TelephonyManager) mAppContext.getSystemService(Context.TELEPHONY_SERVICE))
            .getCallState() == TelephonyManager.CALL_STATE_RINGING;
    // we might have missed an alarm alert
    // TODO: find a way
    // alarm_firing =
    // ((TelephonyManager)
    // mAppContext.getSystemService(Context.TELEPHONY_SERVICE)).getCallState()
    // == TelephonyManager.CALL_STATE_RINGING;
    Intent stateIntent = mAppContext.registerReceiver(null, new IntentFilter(CoreReceiver.TORCH_STATE_CHANGED));
    torch_on = stateIntent != null && stateIntent.getIntExtra("state", 0) != 0;

    init = true;
}

From source file:com.android.screenspeak.eventprocessor.AccessibilityEventProcessor.java

/**
 * Returns whether the device should drop this event. Caches notifications
 * if necessary./*from ww w.ja  va2s  . com*/
 *
 * @param event The current event.
 * @return {@code true} if the event should be dropped.
 */
private boolean shouldDropEvent(AccessibilityEvent event) {
    // Always drop null events.
    if (event == null) {
        return true;
    }

    // Always drop events if the service is suspended.
    if (!ScreenSpeakService.isServiceActive()) {
        return true;
    }

    // If touch exploration is enabled, drop automatically generated events
    // that are sent immediately after a window state change... unless we
    // decide to keep the event.
    if (AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager)
            && ((event.getEventType() & AUTOMATIC_AFTER_STATE_CHANGE) != 0)
            && ((event.getEventTime() - mLastWindowStateChanged) < DELAY_AUTO_AFTER_STATE)
            && !shouldKeepAutomaticEvent(event)) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop event after window state change");
        }
        return true;
    }

    // Real notification events always have parcelable data.
    final boolean isNotification = (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
            && (event.getParcelableData() != null);

    final boolean isPhoneActive = (mCallStateMonitor != null)
            && (mCallStateMonitor.getCurrentCallState() != TelephonyManager.CALL_STATE_IDLE);
    final boolean shouldSpeakCallerId = (mSpeakCallerId && (mCallStateMonitor != null)
            && (mCallStateMonitor.getCurrentCallState() == TelephonyManager.CALL_STATE_RINGING));

    if (mRingerModeAndScreenMonitor != null && !mRingerModeAndScreenMonitor.isScreenOn()
            && !shouldSpeakCallerId) {
        if (!mSpeakWhenScreenOff) {
            // If the user doesn't allow speech when the screen is
            // off, drop the event immediately.
            if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
                Log.v(LOGTAG, "Drop event due to screen state and user pref");
            }
            return true;
        } else if (!isNotification) {
            // If the user allows speech when the screen is off, drop
            // all non-notification events.
            if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
                Log.v(LOGTAG, "Drop non-notification event due to screen state");
            }
            return true;
        }
    }

    final boolean canInterruptRadialMenu = AccessibilityEventUtils.eventMatchesAnyType(event,
            MASK_EVENT_TYPES_INTERRUPT_RADIAL_MENU);
    final boolean silencedByRadialMenu = (mService.getMenuManager().isMenuShowing() && !canInterruptRadialMenu);

    // Don't speak events that cannot interrupt the radial menu, if showing
    if (silencedByRadialMenu) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop event due to radial menu state");
        }
        return true;
    }

    // Don't speak notification events if the user is touch exploring or a phone call is active.
    if (isNotification && (mIsUserTouchExploring || isPhoneActive)) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop notification due to touch or phone state");
        }
        return true;
    }

    final int touchscreenState = mService.getResources().getConfiguration().touchscreen;
    final boolean isTouchInteractionStateChange = AccessibilityEventUtils.eventMatchesAnyType(event,
            MASK_EVENT_TYPES_TOUCH_STATE_CHANGES);

    // Drop all events related to touch interaction state on devices that don't support touch.
    return (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange;
}

From source file:org.chirpradio.mobile.PlaybackService.java

private void setupTelephonyHooks() {
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

    phoneStateListener = new PhoneStateListener() {

        @Override/*  w  w  w . j a va 2 s  . c o m*/
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_OFFHOOK:
            case TelephonyManager.CALL_STATE_RINGING:
                if (isPlaying) {
                    Debug.log(this, "call began, stopping...");
                    stop();
                    isInCall = true;
                }
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                if (isInCall) {
                    isInCall = false;
                    Debug.log(this, "call ended; resuming...");
                    start();
                }
                break;
            }
        }
    };

    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}