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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    settings = getSharedPreferences(PREFS_NAME, 0);
    storedKey = settings.getString("key", null);
    userConsent = settings.getBoolean("userconsent", false);
    context = this;

    // getting device id like IMEI no.
    TelephonyManager tMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mDeviceId = tMgr.getDeviceId();//  ww  w.  ja  v a 2 s .  co  m

    if (userConsent == false) {
        showTerms();
    } else if (storedKey == null) {

        try {
            new GetKey(this).execute(new URI(Utils.getConfigProperty(getResources(), "generate-key") + mDeviceId
                    + Utils.getConfigProperty(getResources(), "securekey")));
        } catch (URISyntaxException e1) {
            Log.d("main activity key generate", e1.toString());
        }
    }

}

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

/**
 * /*from   ww  w  . j av a 2  s .  co 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:crow.util.Util.java

/**
 * ?? ?? android_id /*  w w w  .j  a  v  a 2 s.com*/
 * 
 * @param context
 * @return null ? ???0
 */
public static String getDeviceId(Context context) {
    TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telManager.getDeviceId();
    if (imei != null) {
        return imei;
    }
    String dv = null;
    if ((dv = Settings.Secure.getString(context.getContentResolver(), Secure.ANDROID_ID)) != null) {
        dv = md5(dv).toUpperCase();
    }
    return dv;
}

From source file:pl.llp.aircasting.guice.AirCastingModule.java

@Override
protected void configure() {
    requestStaticInjection(HttpBuilder.class);

    bind(Gson.class).toProvider(GsonProvider.class).in(Scopes.SINGLETON);

    bind(HttpClient.class).to(DefaultHttpClient.class);

    bind(AirCastingDB.class).toProvider(AirCastingDBProvider.class);

    bind(NoteOverlay.class).toProvider(NoteOverlayProvider.class);

    bind(Geocoder.class).toProvider(GeocoderProvider.class);

    bind(EventBus.class).in(Scopes.SINGLETON);

    bindConstant().annotatedWith(SharedPreferencesName.class).to("pl.llp.aircasting_preferences");

    bind(BluetoothAdapter.class).toProvider(BluetoothAdapterProvider.class);

    bind(TelephonyManager.class)
            .toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
}

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

private boolean doOnCallAction(JSONArray args, CallbackContext callbackContext) {
    try {//ww  w .  j a v a 2  s .c om
        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:me.ziccard.secureit.async.upload.AuthenticatorTask.java

public AuthenticatorTask(Activity activity, String username, String password) {
    this.activity = activity;
    this.username = username;
    this.password = password;
    this.manager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns the network operator name/*from  www  .j a  va 2  s.  co  m*/
*/
public JSONArray getNetworkOperatorName() {
    JSONArray jsonArray = null;
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (CommonUtilities.DEBUG_MODE_ENABLED) {
        Log.e("Network OP", tm.getSimOperatorName());
    }
    if (tm.getSimOperatorName() != null && tm.getSimOperatorName() != "") {
        networkOperatorName = tm.getSimOperatorName();
    } else {
        networkOperatorName = "No Sim";
    }

    SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
    try {
        jsonArray = new JSONArray(mainPref.getString("operators", "[]"));
        boolean simstatus = false;
        if (jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                if ((jsonArray.getString(i) != null)
                        && jsonArray.getString(i).trim().equals(tm.getSimOperatorName())) {
                    simstatus = true;
                }
            }
            if (!simstatus) {
                jsonArray.put(tm.getSimOperatorName());
            }
        } else {
            jsonArray.put(tm.getSimOperatorName());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    Editor editor = mainPref.edit();
    editor.putString("operators", jsonArray.toString());
    editor.commit();

    return jsonArray;
}

From source file:com.aegiswallet.tasks.SendShamirValueTask.java

@Override
protected Object doInBackground(Object[] objects) {

    httpclient = new DefaultHttpClient();
    httppost = new HttpPost(Constants.AEGIS_SITE);

    Log.d(TAG, "sending shamir");
    try {/*from  w w w.j  a  va  2s  .c  o m*/
        // Add your data

        TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String uid = tManager.getDeviceId();

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("device", uid));
        nameValuePairs.add(new BasicNameValuePair("message", x3Value));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        int statusCode = response.getStatusLine().getStatusCode();

        Log.d(TAG, "response for shamir: " + statusCode);

        if (statusCode != 200) {
            //TODO: did not succeed
        } else {
            //Means we have successfully exported the key to BitcoinSecurityProject.org
            application.getPrefs().edit().remove(Constants.SHAMIR_EXPORTED_KEY).commit();
        }

    } catch (ClientProtocolException e) {
        Log.d(TAG, e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, e.getMessage());
    }
    return null;
}

From source file:com.karpenstein.signalmon.SignalMonitorActivity.java

/** Called when the activity is first created. */
@Override//from   w  w  w.  java  2 s.c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get the UI
    textOut = (TextView) findViewById(R.id.textOut);

    // Get the telephony manager
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    // Create a new PhoneStateListener
    listener = new PhoneStateListener() {
        @Override
        public void onDataActivity(int direction) {
            String dirString = "N/A";
            switch (direction) {
            case TelephonyManager.DATA_ACTIVITY_NONE:
                dirString = "DATA_ACTIVITY_NONE";
                break;
            case TelephonyManager.DATA_ACTIVITY_IN:
                dirString = "DATA_ACTIVITY_IN";
                break;
            case TelephonyManager.DATA_ACTIVITY_OUT:
                dirString = "DATA_ACTIVITY_OUT";
                break;
            case TelephonyManager.DATA_ACTIVITY_INOUT:
                dirString = "DATA_ACTIVITY_INOUT";
                break;
            case TelephonyManager.DATA_ACTIVITY_DORMANT:
                dirString = "DATA_ACTIVITY_DORMANT";
                break;
            }
            textOut.append(dirString + "\n");
        }

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            textOut.append(signalStrength.toString() + "\n");
        }

        @Override
        public void onDataConnectionStateChanged(int state, int networkType) {
            String stateString = "N/A";
            String netTypString = "N/A";
            switch (state) {
            case TelephonyManager.DATA_CONNECTED:
                stateString = "DATA_CONNECTED";
                break;
            case TelephonyManager.DATA_CONNECTING:
                stateString = "DATA_CONNECTING";
                break;
            case TelephonyManager.DATA_DISCONNECTED:
                stateString = "DATA_DISCONNECTED";
                break;
            case TelephonyManager.DATA_SUSPENDED:
                stateString = "DATA_SUSPENDED";
                break;
            }
            switch (networkType) {
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                netTypString = "NETWORK_TYPE_1xRTT";
                break;
            case TelephonyManager.NETWORK_TYPE_CDMA:
                netTypString = "NETWORK_TYPE_CDMA";
                break;
            case TelephonyManager.NETWORK_TYPE_EDGE:
                netTypString = "NETWORK_TYPE_EDGE";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                netTypString = "NETWORK_TYPE_EVDO_0";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                netTypString = "NETWORK_TYPE_EVDO_A";
                break;
            case TelephonyManager.NETWORK_TYPE_GPRS:
                netTypString = "NETWORK_TYPE_GPRS";
                break;
            case TelephonyManager.NETWORK_TYPE_HSDPA:
                netTypString = "NETWORK_TYPE_HSDPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSPA:
                netTypString = "NETWORK_TYPE_HSPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSUPA:
                netTypString = "NETWORK_TYPE_HSUPA";
                break;
            case TelephonyManager.NETWORK_TYPE_IDEN:
                netTypString = "NETWORK_TYPE_IDE";
                break;
            case TelephonyManager.NETWORK_TYPE_UMTS:
                netTypString = "NETWORK_TYPE_UMTS";
                break;
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                netTypString = "NETWORK_TYPE_UNKNOWN";
                break;
            }
            textOut.append(String.format("onDataConnectionStateChanged: %s; %s\n", stateString, netTypString));
        }
    };

    // Register the listener with the telephony manager
    telephonyManager.listen(listener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
            | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_DATA_ACTIVITY);

    // start the NetServerService
    startService(new Intent(this, NetServerService.class));
}

From source file:com.quantcast.measurement.service.QCPolicy.java

public static QCPolicy getQuantcastPolicy(Context context, String apiKey, String networkCode,
        String packageName, boolean kidDirected) {
    Uri.Builder builder = Uri.parse(QCUtility.addScheme(POLICY_REQUEST_BASE_WITHOUT_SCHEME)).buildUpon();
    builder.appendQueryParameter(POLICY_REQUEST_API_VERSION_PARAMETER, QCUtility.API_VERSION);
    builder.appendQueryParameter(POLICY_REQUEST_DEVICE_TYPE_PARAMETER, POLICY_REQUEST_DEVICE_TYPE);

    String mcc = null;//from w  w w.  j a  v a 2  s .c o m
    try {
        TelephonyManager tel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (tel != null) {
            mcc = tel.getNetworkCountryIso();
            if (mcc == null) {
                mcc = tel.getSimCountryIso();
            }
        }
    } catch (SecurityException ignored) {
    }

    if (mcc == null) {
        mcc = Locale.getDefault().getCountry();
    }
    if (mcc != null) {
        builder.appendQueryParameter(POLICY_REQUEST_DEVICE_COUNTRY, mcc);
    }

    if (apiKey != null) {
        builder.appendQueryParameter(POLICY_REQUEST_API_KEY_PARAMETER, apiKey);
    } else {
        builder.appendQueryParameter(POLICY_REQUEST_NETWORK_CODE_PARAMETER, networkCode);
        builder.appendQueryParameter(POLICY_REQUEST_PACKAGE_PARAMETER, packageName);
    }

    if (kidDirected) {
        builder.appendQueryParameter(POLICY_REQUEST_KID_DIRECTED_PARAMETER, "YES");
    }

    Uri builtURL = builder.build();
    if (builtURL != null) {
        return new QCPolicy(context, builtURL.toString());
    } else {
        QCLog.e(TAG, "Policy URL was not built correctly for some reason.  Should not happen");
        return null;
    }
}