Example usage for android.content Context TELEPHONY_SERVICE

List of usage examples for android.content Context TELEPHONY_SERVICE

Introduction

In this page you can find the example usage for android.content Context TELEPHONY_SERVICE.

Prototype

String TELEPHONY_SERVICE

To view the source code for android.content Context TELEPHONY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.

Usage

From source file:ly.count.android.api.DeviceInfoTests.java

public void testGetCarrier_nullTelephonyManager() {
    final Context mockContext = mock(Context.class);
    when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(null);
    assertEquals("", DeviceInfo.getCarrier(mockContext));
}

From source file:io.lqd.sdk.model.LQDevice.java

private static String getCarrier(Context context) {
    TelephonyManager telephonyManager = ((TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE));
    return telephonyManager.getNetworkOperatorName();
}

From source file:eu.liveGov.libraries.livegovtoolkit.helper.UserInformationHelper.java

public void requestNewAnonymous(Context con) {
    logger.info("requestNewAnonymous;");
    _context = con;//from w ww. j a v  a 2  s  .  com
    final TelephonyManager tm = (TelephonyManager) con.getSystemService(Context.TELEPHONY_SERVICE);

    String deviceId = tm.getDeviceId();
    logger.info("requestNewAnonymous; id: A_" + deviceId);
    new DownloadHelper(this).createAnonymousUser("A_" + deviceId);
}

From source file:ly.count.android.api.DeviceInfoTests.java

public void testGetCarrier_nullNetOperator() {
    final TelephonyManager mockTelephonyManager = mock(TelephonyManager.class);
    when(mockTelephonyManager.getNetworkOperatorName()).thenReturn(null);
    final Context mockContext = mock(Context.class);
    when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager);
    assertEquals("", DeviceInfo.getCarrier(mockContext));
}

From source file:com.mpower.mintel.android.application.MIntel.java

public static String getDeviceId() {
    TelephonyManager tm = (TelephonyManager) getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getDeviceId();
}

From source file:eu.cyberkat.h2owirelessbalancecheck.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_about:
        PackageInfo pInfo = null;//from   ww w .j a  va  2s .c  om
        try {
            pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (NameNotFoundException e) {
            pInfo = null;
        }
        if (pInfo == null) {
            return false;
        }
        String version = pInfo.versionName;
        int versionCode = pInfo.versionCode;
        Context aboutToastContext = getApplicationContext();
        CharSequence aboutToastText = "H2O Data Balance v" + version + ", (" + ordinal(versionCode)
                + " Revision)\nCopyright (c) 2014, Dylan J. Morrison <insidious@cyberkat.eu>, Licensed under the ISC license.";
        int aboutToastDuration = Toast.LENGTH_LONG;
        Toast aboutToast = Toast.makeText(aboutToastContext, aboutToastText, aboutToastDuration);
        aboutToast.show();
        return true;
    case R.id.action_grabnum:
        TelephonyManager tMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        if (mPhoneNumber == null) {
            Context numberErrorContext = getApplicationContext();
            CharSequence numberErrorText = "Unable to get device phone number.";
            int numberErrorDuration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(numberErrorContext, numberErrorText, numberErrorDuration);
            toast.show();
        } else {
            EditText textbox = (EditText) this.findViewById(R.id.editText2);
            mPhoneNumber = mPhoneNumber.replaceAll("[^\\d]", "");
            textbox.setText(mPhoneNumber);
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.hfoss.posit.android.web.Communicator.java

public Communicator(Context _context) {
    mContext = _context;//from ww w .  j av  a 2 s .  c  o m
    mTotalTime = 0;
    mStart = 0;

    mHttpParams = new BasicHttpParams();

    // Set the timeout in milliseconds until a connection is established.
    HttpConnectionParams.setConnectionTimeout(mHttpParams, CONNECTION_TIMEOUT);

    // Set the default socket timeout (SO_TIMEOUT) 
    // in milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setSoTimeout(mHttpParams, SOCKET_TIMEOUT);

    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", new PlainSocketFactory(), 80));
    mConnectionManager = new ThreadSafeClientConnManager(mHttpParams, registry);
    mHttpClient = new DefaultHttpClient(mConnectionManager, mHttpParams);

    PreferenceManager.setDefaultValues(mContext, R.xml.posit_preferences, false);
    applicationPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    setApplicationAttributes(applicationPreferences.getString("AUTHKEY", ""),
            applicationPreferences.getString("SERVER_ADDRESS", server),
            applicationPreferences.getInt("PROJECT_ID", projectId));
    TelephonyManager manager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    imei = manager.getDeviceId();

}

From source file:ly.count.android.api.DeviceInfoTests.java

public void testGetCarrier_emptyNetOperator() {
    final TelephonyManager mockTelephonyManager = mock(TelephonyManager.class);
    when(mockTelephonyManager.getNetworkOperatorName()).thenReturn("");
    final Context mockContext = mock(Context.class);
    when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager);
    assertEquals("", DeviceInfo.getCarrier(mockContext));
}

From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java

private void setSpinnerCountry(Spinner spinner) {
    TelephonyManager tel = (TelephonyManager) getApplicationContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
    String country = tel.getSimCountryIso();
    Log.i(tag, "country: " + country);
    if (Text.isEmpty(country)) {
        spinner.setSelection(92); // India
        return;/*from  w w w. j  a  v  a 2 s .c o  m*/
    }
    CountryMap m = new CountryMap();
    Log.i(tag, "index: " + m.getIndex(country.toUpperCase()));
    spinner.setSelection(m.getIndex(country.toUpperCase()));
    Log.i(tag, "country: " + m.getCallingCode(country.toUpperCase()));
}