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:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}

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

@Override
public void onReceive(Context context, Intent intent) {
    MyPhoneStateListener phoneListener = new MyPhoneStateListener(
            context.getSharedPreferences("fantecremote", 0));
    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}

From source file:es.warp.desktop_droid.TelephonyEventService.java

@Override
public void onCreate() {
    Toast.makeText(this, "My service created", Toast.LENGTH_LONG);
    Log.d("TelephonyEventService", "onCreate");
    TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    manager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}

From source file:es.warp.desktop_droid.TelephonyEventService.java

@Override
public void onDestroy() {
    Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG);
    Log.d("TelephonyEventService", "onDestroy");
    TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    manager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}

From source file:me.tassoevan.cordova.PhoneTrapPlugin.java

private boolean doOnCallAction(JSONArray args, CallbackContext callbackContext) {
    try {/*from  w ww .j  av  a2s .  co m*/
        if (listener == null) {
            listener = new CallStateListener();
            TelephonyManager TelephonyMgr = (TelephonyManager) cordova.getActivity()
                    .getSystemService(Context.TELEPHONY_SERVICE);
            TelephonyMgr.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
        }

        listener.callbackContext = callbackContext;

        return true;
    } catch (Exception e) {
        this.logError("Exception occurred: ".concat(e.getMessage()));
        callbackContext.error("Exception occurred: ".concat(e.getMessage()));
        return false;
    }
}

From source file:fr.inria.ucn.listeners.MyPhoneStateListener.java

/**
 * /*from   ww w  . j  av a  2  s. c  o  m*/
 * @param c
 */
public void disable(Context c) {
    TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
        tm.listen(this, PhoneStateListener.LISTEN_NONE);
        this.c = null;
    } // else no telephony
}

From source file:fr.inria.ucn.listeners.MyPhoneStateListener.java

/**
 * /*from  w ww.jav a  2s.c  o  m*/
 * @param c
 */
public void enable(Context c) {
    TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
        tm.listen(this,
                PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
        this.c = c;
    } // else no telephony
}

From source file:ru.piter.fm.activities.RadioActivity.java

private void initUI() {
    setContentView(R.layout.main);/*from   ww  w .j  a  v a2 s . c o m*/

    mPager = (ViewPager) findViewById(R.id.pager);
    mAdapter = new RadioAdapter(getSupportFragmentManager());
    actionBar = getSupportActionBar();

    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    getSupportActionBar().setDisplayShowTitleEnabled(true);

    actionBar.addTab(actionBar.newTab().setText("PITER FM").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("MOSKVA FM").setTabListener(this));

    mAdapter.addFragment(new RadioFragment(RadioFactory.getRadio(RadioFactory.PITER_FM)));
    mAdapter.addFragment(new RadioFragment(RadioFactory.getRadio(RadioFactory.MOSKVA_FM)));

    mPager.setAdapter(mAdapter);
    mPager.setOnPageChangeListener(this);

    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    tm.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

}

From source file:jp.morihirosoft.twwb.TwwbService.java

private void registerReceivers() {
    if (DEBUG)/*w  ww.j a  va 2  s. c om*/
        Log.d(TAG, "registerReceivers");
    if (!mIsRegistered) {
        mIsRegistered = true;
        registerReceiver(mReceiverScreenOn, new IntentFilter(Intent.ACTION_SCREEN_ON));
        registerReceiver(mReceiverScreenOff, new IntentFilter(Intent.ACTION_SCREEN_OFF));
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
        lbm.registerReceiver(mReceiverRecognition, new IntentFilter(Constants.ACTION_RECOGNITION));
    }
}

From source file:jp.morihirosoft.twwb.TwwbService.java

private void unregisterReceivers() {
    if (DEBUG)/*ww w .j a  v a2  s .c om*/
        Log.d(TAG, "unregisterReceivers");
    if (mIsRegistered) {
        mIsRegistered = false;
        unregisterReceiver(mReceiverScreenOn);
        unregisterReceiver(mReceiverScreenOff);
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
        lbm.unregisterReceiver(mReceiverRecognition);
    }
}