Example usage for android.telephony PhoneStateListener LISTEN_CELL_LOCATION

List of usage examples for android.telephony PhoneStateListener LISTEN_CELL_LOCATION

Introduction

In this page you can find the example usage for android.telephony PhoneStateListener LISTEN_CELL_LOCATION.

Prototype

int LISTEN_CELL_LOCATION

To view the source code for android.telephony PhoneStateListener LISTEN_CELL_LOCATION.

Click Source Link

Document

Listen for changes to the device's cell location.

Usage

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

/**
 * //ww w  .  j  ava  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:uk.ac.horizon.ubihelper.service.channel.CellStrengthChannel.java

@Override
protected void handleStart() {
    if (telephony != null) {
        telephony.listen(listener,/*from   ww  w  .ja va2s.  co  m*/
                PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_CELL_LOCATION);
    }
}

From source file:com.tvs.signaltracker.STService.java

private void InitBase() {
    Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    MyListener = new MyPhoneStateListener();

    mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    NetLocListener = new NETLocationListener();
    mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 10, NetLocListener);
    Tel.listen(MyListener,//from w w w.  j a  va 2 s .  c  om
            PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_CELL_LOCATION);
    //CommonHandler.Operator   =   Utils.DoOperator(Tel.getNetworkOperatorName());
    Operator x = CommonHandler.dbman.getOperator(CommonHandler.MCC, CommonHandler.MNC);
    if (x != null)
        CommonHandler.Operator = x.name;
    else
        CommonHandler.Operator = CommonHandler.MCC + "" + CommonHandler.MNC;
}

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

/**
 * Called when the activity is first created.
 *///from  www.j  a  v a  2 s . c om
@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 w  w w .jav a2 s  . co  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.activities.MapViewerOsmDroid.java

/**
 * Called when the activity is first created.
 *///w  ww  . ja  v  a 2s .  co  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.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  ava 2 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.odo.kcl.mobileminer.miner.MinerService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    startTime = new Date();
    //Log.i("MinerService","started mining");
    int phoneFlags;

    phoneFlags = PhoneStateListener.LISTEN_DATA_ACTIVITY | PhoneStateListener.LISTEN_CELL_LOCATION;

    /**//from   ww w  .  ja va 2 s.  c o  m
     if (Build.VERSION.SDK_INT >= 17) {
     // http://code.google.com/p/android/issues/detail?id=43467
     // http://stackoverflow.com/questions/20049510/oncellinfochanged-callback-is-always-null
     phoneFlags = PhoneStateListener.LISTEN_DATA_ACTIVITY|PhoneStateListener.LISTEN_CELL_INFO
     |PhoneStateListener.LISTEN_SIGNAL_STRENGTHS;
     }
     else {
     phoneFlags = PhoneStateListener.LISTEN_DATA_ACTIVITY|PhoneStateListener.LISTEN_CELL_LOCATION;
     }
     **/

    ((TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE)).listen(phoneListener, phoneFlags);
    Toast.makeText(this, "Started Mining...", Toast.LENGTH_SHORT).show();
    moveToForeground();
    return START_STICKY;
}

From source file:com.secupwn.aimsicd.service.CellTracker.java

/**
 *  Description:    Cell Information Tracking and database logging
 *
 *          TODO: update this!!/*w w  w  . ja  v a 2 s.co m*/
 *
 *          If the "tracking" option is enabled (as it is by default) then we are keeping
 *          a record (tracking) of the device location "gpsd_lat/lon", the connection
 *          signal strength (rx_signal) and data activity (?) and data connection state (?).
 *
 *          The items included in these are stored in the "DBi_measure" table.
 *
 *          DATA_ACTIVITY:
 *          DATA_CONNECTION_STATE:
 *
 *
 *  UI/function:        Drawer:  "Toggle Cell Tracking"
 *
 *  Issues:
 *
 *  Notes:              TODO:   We also need to listen and log for:
 *
 *      [ ]     LISTEN_CALL_STATE:
 *                  CALL_STATE_IDLE
 *                  CALL_STATE_OFFHOOK
 *                  CALL_STATE_RINGING
 *
 *      [ ]     LISTEN_SERVICE_STATE:
 *                  STATE_EMERGENCY_ONLY
 *                  STATE_IN_SERVICE
 *                  STATE_OUT_OF_SERVICE
 *                  STATE_POWER_OFF
 *
 * @param track Enable/Disable tracking
 */
public void setCellTracking(boolean track) {
    if (track) {
        tm.listen(cellSignalListener, PhoneStateListener.LISTEN_CELL_LOCATION | // gpsd_lat/lon ?
                PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | // rx_signal
                PhoneStateListener.LISTEN_DATA_ACTIVITY | // No,In,Ou,IO,Do
                PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | // Di,Ct,Cd,Su
                PhoneStateListener.LISTEN_CELL_INFO // !? (Need API 17)
        );
        trackingCell = true;
        Helpers.msgShort(context, context.getString(R.string.tracking_cell_information));
    } else {
        tm.listen(cellSignalListener, PhoneStateListener.LISTEN_NONE);
        device.cell.setLon(0.0);
        device.cell.setLat(0.0);
        device.setCellInfo("[0,0]|nn|nn|"); //default entries into "locationinfo"::Connection
        trackingCell = false;
        Helpers.msgShort(context, context.getString(R.string.stopped_tracking_cell_information));
    }
    setNotification();
}

From source file:com.github.nutomic.pegasus.LocationService.java

/**
 * Register CellListener and show Notification.
 *///from  w ww  .j  av a 2s  . c o  m
@Override
public void onCreate() {
    super.onCreate();
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mCellListener = new CellListener(tm.getPhoneType());
    tm.listen(mCellListener, PhoneStateListener.LISTEN_CELL_LOCATION);
    // Force update.
    mCellListener.onCellLocationChanged(tm.getCellLocation());
}