Search in sources :

Example 11 with PhoneStateListener

use of android.telephony.PhoneStateListener in project PLDroidPlayer by pili-engineering.

the class PLAudioPlayerActivity method startTelephonyListener.

// Listen to the telephone
private void startTelephonyListener() {
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephonyManager == null) {
        Log.e(TAG, "Failed to initialize TelephonyManager!!!");
        return;
    }
    mPhoneStateListener = new PhoneStateListener() {

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            // TODO Auto-generated method stub
            super.onCallStateChanged(state, incomingNumber);
            switch(state) {
                case TelephonyManager.CALL_STATE_IDLE:
                    Log.d(TAG, "PhoneStateListener: CALL_STATE_IDLE");
                    if (mMediaPlayer != null) {
                        mMediaPlayer.start();
                    }
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    Log.d(TAG, "PhoneStateListener: CALL_STATE_OFFHOOK");
                    if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
                        mMediaPlayer.pause();
                    }
                    break;
                case TelephonyManager.CALL_STATE_RINGING:
                    Log.d(TAG, "PhoneStateListener: CALL_STATE_RINGING: " + incomingNumber);
                    break;
            }
        }
    };
    try {
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PhoneStateListener(android.telephony.PhoneStateListener) IOException(java.io.IOException)

Example 12 with PhoneStateListener

use of android.telephony.PhoneStateListener in project android_frameworks_base by ParanoidAndroid.

the class ComprehensiveCountryDetector method addPhoneStateListener.

protected synchronized void addPhoneStateListener() {
    if (mPhoneStateListener == null) {
        mPhoneStateListener = new PhoneStateListener() {

            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                mCountServiceStateChanges++;
                mTotalCountServiceStateChanges++;
                if (!isNetworkCountryCodeAvailable()) {
                    return;
                }
                if (DEBUG)
                    Slog.d(TAG, "onServiceStateChanged: " + serviceState.getState());
                detectCountry(true, true);
            }
        };
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    }
}
Also used : ServiceState(android.telephony.ServiceState) PhoneStateListener(android.telephony.PhoneStateListener)

Example 13 with PhoneStateListener

use of android.telephony.PhoneStateListener in project platform_frameworks_base by android.

the class ComprehensiveCountryDetector method addPhoneStateListener.

protected synchronized void addPhoneStateListener() {
    if (mPhoneStateListener == null) {
        mPhoneStateListener = new PhoneStateListener() {

            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                mCountServiceStateChanges++;
                mTotalCountServiceStateChanges++;
                if (!isNetworkCountryCodeAvailable()) {
                    return;
                }
                if (DEBUG)
                    Slog.d(TAG, "onServiceStateChanged: " + serviceState.getState());
                detectCountry(true, true);
            }
        };
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    }
}
Also used : ServiceState(android.telephony.ServiceState) PhoneStateListener(android.telephony.PhoneStateListener)

Example 14 with PhoneStateListener

use of android.telephony.PhoneStateListener in project android_frameworks_base by DirtyUnicorns.

the class ComprehensiveCountryDetector method addPhoneStateListener.

protected synchronized void addPhoneStateListener() {
    if (mPhoneStateListener == null) {
        mPhoneStateListener = new PhoneStateListener() {

            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                mCountServiceStateChanges++;
                mTotalCountServiceStateChanges++;
                if (!isNetworkCountryCodeAvailable()) {
                    return;
                }
                if (DEBUG)
                    Slog.d(TAG, "onServiceStateChanged: " + serviceState.getState());
                detectCountry(true, true);
            }
        };
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    }
}
Also used : ServiceState(android.telephony.ServiceState) PhoneStateListener(android.telephony.PhoneStateListener)

Example 15 with PhoneStateListener

use of android.telephony.PhoneStateListener in project android_frameworks_base by ResurrectionRemix.

the class ComprehensiveCountryDetector method addPhoneStateListener.

protected synchronized void addPhoneStateListener() {
    if (mPhoneStateListener == null) {
        mPhoneStateListener = new PhoneStateListener() {

            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                mCountServiceStateChanges++;
                mTotalCountServiceStateChanges++;
                if (!isNetworkCountryCodeAvailable()) {
                    return;
                }
                if (DEBUG)
                    Slog.d(TAG, "onServiceStateChanged: " + serviceState.getState());
                detectCountry(true, true);
            }
        };
        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    }
}
Also used : ServiceState(android.telephony.ServiceState) PhoneStateListener(android.telephony.PhoneStateListener)

Aggregations

PhoneStateListener (android.telephony.PhoneStateListener)15 ServiceState (android.telephony.ServiceState)10 TelephonyManager (android.telephony.TelephonyManager)4 Paint (android.graphics.Paint)2 SubscriptionInfo (android.telephony.SubscriptionInfo)2 BitSet (java.util.BitSet)2 Dialog (android.app.Dialog)1 ComponentName (android.content.ComponentName)1 IntentFilter (android.content.IntentFilter)1 ServiceConnection (android.content.ServiceConnection)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Handler (android.os.Handler)1 IBinder (android.os.IBinder)1 NavigationView (android.support.design.widget.NavigationView)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 SignalStrength (android.telephony.SignalStrength)1