Example usage for android.telephony TelephonyManager listen

List of usage examples for android.telephony TelephonyManager listen

Introduction

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

Prototype

public void listen(PhoneStateListener listener, int events) 

Source Link

Document

Registers a listener object to receive notification of changes in specified telephony states.

Usage

From source file:ru.org.sevn.audiobookplayer.AppService.java

@Override
public void onCreate() {
    defaultIcon = BitmapFactory.decodeResource(getResources(), R.drawable.picture);
    defaultIcon = Util.getScaledImage(defaultIcon, ICON_SIZE, ICON_SIZE, Util.getImageFactor(getResources()));

    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    super.onCreate();
    mp3Player.initialize();//from  ww  w.ja va2s.c om
    restoreSettings();
    mp3Player.getMediaPlayer().addChangeStateListener(this);
    mp3Player.getAppSettings().addPropertyChangeListener(this);

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

    musicIntentReceiver = new MusicIntentReceiver();
    registerReceiver(musicIntentReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));

}

From source file:com.SecUpwN.AIMSICD.activities.MapViewerOsmDroid.java

@Override
protected void onDestroy() {
    super.onDestroy();
    prefs.unregisterOnSharedPreferenceChangeListener(this);
    // Unbind from the service
    if (mBound) {
        mContext.unbindService(mConnection);
        mBound = false;/*from   w w  w  .j  a va 2 s  .  c  o m*/
    }

    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);

    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
}

From source file:com.SecUpwN.AIMSICD.activities.MapViewerOsmDroid.java

/**
 * Called when the activity is first created.
 *///from   ww  w.ja  va  2s . c o m
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Starting MapViewer");
    super.onCreate(savedInstanceState);
    mContext = this;

    setContentView(R.layout.map);
    setUpMapIfNeeded();

    mDbHelper = new AIMSICDDbAdapter(mContext);

    // Bind to LocalService
    Intent intent = new Intent(mContext, AimsicdService.class);
    mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener,
            PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}

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

private void initPhoneCallListener() {
    PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override//  w w w  . ja v a 2 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:com.secupwn.aimsicd.ui.activities.MapViewerOsmDroid.java

@Override
protected void onDestroy() {
    super.onDestroy();
    prefs.unregisterOnSharedPreferenceChangeListener(this);
    // Unbind from the service
    if (mBound) {
        unbindService(mConnection);/*from  w  ww.ja v a 2s . co  m*/
        mBound = false;
    }

    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);

    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
}

From source file:com.secupwn.aimsicd.ui.activities.MapViewerOsmDroid.java

/**
 * Called when the activity is first created.
 *///w w  w .j  a  v  a  2s.c  o m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    log.info("Starting MapViewer");

    setUpMapIfNeeded();

    mDbHelper = new RealmHelper(this);
    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    // Bind to LocalService
    Intent intent = new Intent(this, AimsicdService.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener,
            PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}

From source file:com.SecUpwN.AIMSICD.fragments.MapFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    log.info("Starting MapViewer");

    setUpMapIfNeeded();//from  www  .  j  a va  2  s.  c  o  m

    mDbHelper = new AIMSICDDbAdapter(getActivity());
    tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);

    // Bind to LocalService
    Intent intent = new Intent(getActivity(), AimsicdService.class);
    getActivity().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener,
            PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}

From source file:com.SecUpwN.AIMSICD.fragments.MapFragment.java

@Override
public void onDestroyView() {
    super.onDestroy();

    LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver);
    if (mCompassOverlay != null) {
        mCompassOverlay.disableCompass();
    }/*from  w ww .j a  v  a2 s . com*/

    if (mMyLocationOverlay != null) {
        mMyLocationOverlay.disableMyLocation();
    }

    prefs.unregisterOnSharedPreferenceChangeListener(this);
    // Unbind from the service
    if (mBound) {
        getActivity().unbindService(mConnection);
        mBound = false;
    }

    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);

    LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver);
}

From source file:com.secupwn.aimsicd.ui.fragments.MapFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    log.info("Starting MapViewer");

    setUpMapIfNeeded();//from   www . j  av a2 s  . c  om

    mDbHelper = new RealmHelper(getActivity());
    tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);

    // Bind to LocalService
    Intent intent = new Intent(getActivity(), AimsicdService.class);
    getActivity().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener,
            PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}

From source file:com.secupwn.aimsicd.ui.fragments.MapFragment.java

@Override
public void onDestroyView() {
    super.onDestroyView();

    LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver);
    if (mCompassOverlay != null) {
        mCompassOverlay.disableCompass();
    }//from   w w w.  j a v  a  2s.  c o m

    if (mMyLocationOverlay != null) {
        mMyLocationOverlay.disableMyLocation();
    }

    if (prefs != null) {
        prefs.unregisterOnSharedPreferenceChangeListener(this);
    }
    // Unbind from the service
    if (mBound) {
        getActivity().unbindService(mConnection);
        mBound = false;
    }

    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);

    LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver);
}