Example usage for android.telephony PhoneStateListener LISTEN_SIGNAL_STRENGTHS

List of usage examples for android.telephony PhoneStateListener LISTEN_SIGNAL_STRENGTHS

Introduction

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

Prototype

int LISTEN_SIGNAL_STRENGTHS

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

Click Source Link

Document

Listen for changes to the network signal strengths (cellular).

Usage

From source file:de.inhji.cordova.plugin.Telephony.java

public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    context = this.cordova.getActivity().getApplicationContext();
    tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    listener = new MyPhoneStateListener();
    tm.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

    Log.i(TAG, "Starting PhoneStateListener..");
}

From source file:uk.ac.horizon.ubihelper.service.channel.CellStrengthChannel.java

@Override
protected void handleStart() {
    if (telephony != null) {
        telephony.listen(listener,//from   w  w w. j  av a  2s .  c o  m
                PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_CELL_LOCATION);
    }
}

From source file:com.cc.signalinfo.fragments.SignalFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    setRetainInstance(true);/*w  w  w .  jav  a  2 s  .  co m*/
    activity = getActivity();
    rootView = inflater.inflate(R.layout.main, parent, false);
    rootView.findViewById(R.id.additionalInfo).setOnClickListener(this);
    sigInfoIds = getResources().obtainTypedArray(R.array.sigInfoIds);
    // sigInfoTitles = getResources().getStringArray(R.array.sigInfoTitles);

    SignalListener listener = new SignalListener(this);
    tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    setPhoneInfo();
    formatFooter();

    if (!BuildConfig.DEBUG) {
        AdView ad = (AdView) rootView.findViewById(R.id.adView);
        ad.loadAd(new AdRequest());
    }
    return rootView;
}

From source file:ru.dublgis.androidhelpers.mobility.CellListener.java

public synchronized boolean start() {
    Log.d(TAG, "start");
    try {//from  w  w  w  . j  a va  2 s.c om
        if (mManager == null) {
            mManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
        }

        Runnable listenRunnable = new Runnable() {
            @Override
            public void run() {
                if (mManager != null) {
                    try {
                        Looper.prepare();
                        mListenerLooper = Looper.myLooper();
                        mListener = new CellListenerImpl();
                        mManager.listen(mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
                        Looper.loop();
                        mManager.listen(mListener, PhoneStateListener.LISTEN_NONE);
                    } catch (Throwable ex) {
                        Log.e(TAG, "Failed to start TelephonyManager listener", ex);
                    }
                }
            }
        };

        mListenerThread = new Thread(listenRunnable, "Listen TelephonyManager");
        mListenerThread.start();
        return true;
    } catch (Throwable e) {
        Log.e(TAG, "Exception while starting cell listener: ", e);
        return false;
    }
}

From source file:com.commonsware.cwac.locpoll.demo.LocationReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;/*from w w w.jav  a 2 s .  co  m*/

    File log = new File(Environment.getExternalStorageDirectory(), "LocationLog.txt");

    try {
        BufferedWriter out = new BufferedWriter(new FileWriter(log.getAbsolutePath(), log.exists()));

        out.write(new Date().toString());
        out.write(" : ");

        Bundle b = intent.getExtras();
        loc = (Location) b.get(LocationPoller.EXTRA_LOCATION);
        String msg;

        if (loc == null) {
            loc = (Location) b.get(LocationPoller.EXTRA_LASTKNOWN);

            if (loc == null) {
                msg = intent.getStringExtra(LocationPoller.EXTRA_ERROR);
            } else {
                msg = "TIMEOUT, lastKnown=" + loc.toString();
            }
        } else {
            msg = loc.toString();
            Log.d("Location Poller", msg);

            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

            if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSDPA)) {
                Log.d("Type", "3g");// for 3g HSDPA networktype will be return as
                // per testing(real) in device with 3g enable data
                // and speed will also matters to decide 3g network type
                type = 2;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPAP)) {
                Log.d("Type", "4g"); // /No specification for the 4g but from wiki
                // i found(HSPAP used in 4g)
                // http://goo.gl/bhtVT
                type = 3;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_GPRS)) {
                Log.d("Type", "GPRS");
                type = 1;
            } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE)) {
                Log.d("Type", "EDGE 2g");
                type = 0;
            }

            /* Update the listener, and start it */
            MyListener = new MyPhoneStateListener();
            Tel = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
            Tel.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }

        if (msg == null) {
            msg = "Invalid broadcast received!";
        }

        out.write(msg);
        out.write("\n");
        out.close();
    } catch (IOException e) {
        Log.e(getClass().getName(), "Exception appending to log file", e);
    }
}

From source file:de.mangelow.throughput.NotificationService.java

@Override
public void onCreate() {
    super.onCreate();
    if (D)// ww w . j a  va  2  s .  c  o m
        Log.d(TAG, "Service started");

    context = getApplicationContext();
    res = context.getResources();

    if (tmanager == null) {
        tmanager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        tmanager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mBroadcastReceiver, filter);

    int[] refresh_values = res.getIntArray(R.array.refresh_values);
    long refresh = (long) refresh_values[MainActivity.loadIntPref(context, MainActivity.REFRESH,
            MainActivity.REFRESH_DEFAULT)];

    modifyNotification(R.drawable.ic_stat_zero, null, "", "", new Intent());

    if (handler == null) {
        handler = new Handler();
        handler.postDelayed(mRunnable, refresh);
    }

}

From source file:com.cc.signalinfo.fragments.SignalFragment.java

@Override
public void onResume() {
    super.onResume();
    tm.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}

From source file:com.cc.signalinfo.activities.MainActivity.java

/**
 * Initialize the app.//from   w ww  .j  a v  a 2s.c  om
 *
 * @param savedInstanceState - umm... the saved instance state
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    onCreate(R.layout.main, savedInstanceState);
    SignalListener listener = new SignalListener(this);
    sigInfoIds = getResources().obtainTypedArray(R.array.sigInfoIds);
    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    this.commands = new RootCommands(new RootTerminal(), this);

    getSupportLoaderManager().initLoader(0, null, this);
    findViewById(R.id.additionalInfo).setOnClickListener(this);
    setPhoneInfo();
}

From source file:org.wso2.iot.agent.services.NetworkInfoService.java

@Override
public void onCreate() {
    thisInstance = this;
    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "Creating service");
    }//from w  w w. j  a  v  a  2s .co m
    mapper = new ObjectMapper();
    info = getNetworkInfo();
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(deviceNetworkStatusListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (Constants.WIFI_SCANNING_ENABLED) {
        // Register broadcast receiver
        // Broadcast receiver will automatically call when number of wifi connections changed
        registerReceiver(wifiScanReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        // start scanning wifi
        startWifiScan();
    }
}

From source file:org.most.input.CellInput.java

@Override
public void workToDo() {
    CellLocation cellLocation = _telephonyManager.getCellLocation();
    _telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    nciList = _telephonyManager.getNeighboringCellInfo();
    DataBundle b = _bundlePool.borrowBundle();
    if (cellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmLocation = (GsmCellLocation) cellLocation;
        b.putInt(KEY_GSM_CELL_ID, gsmLocation.getCid());
        b.putInt(KEY_GSM_LAC, gsmLocation.getLac());
        b.putInt(KEY_RSSI, _phoneStateListener.signalStrengthValue);
        // gsmLocation.getPsc() require api 9
        // b.putInt(KEY_GSM_PSC, gsmLocation.getPsc());
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_GSM);
    } else if (cellLocation instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) cellLocation;
        b.putInt(KEY_BASE_STATION_ID, cdmaLocation.getBaseStationId());
        b.putInt(KEY_BASE_STATION_LATITUDE, cdmaLocation.getBaseStationLatitude());
        b.putInt(KEY_BASE_STATION_LONGITUDE, cdmaLocation.getBaseStationLongitude());
        b.putInt(KEY_BASE_NETWORK_ID, cdmaLocation.getNetworkId());
        b.putInt(KEY_BASE_SYSTEM_ID, cdmaLocation.getSystemId());
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_CDMA);
    } else {/*  ww w.  j  a  v  a 2  s  .c  om*/
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_NONE);
    }
    b.putLong(Input.KEY_TIMESTAMP, System.currentTimeMillis());
    b.putInt(Input.KEY_TYPE, Input.Type.CELL.toInt());
    post(b);
    postResults(b, nciList);
    scheduleNextStart();
}