List of usage examples for android.content Context TELEPHONY_SERVICE
String TELEPHONY_SERVICE
To view the source code for android.content Context TELEPHONY_SERVICE.
Click Source Link
From source file:com.polyvi.xface.extension.devicecapability.XDeviceCapabilityExt.java
/** * ?deviceInternational Mobile Equipment Identity(IMEI) * * @param context/*from www . ja v a 2 s . c o m*/ * @return */ private String getImei(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.getDeviceId(); }
From source file:com.vkassin.mtrade.CSPLicense.java
boolean getLicense() { HttpClient httpclient = getNewHttpClient(); HttpPost httppost = new HttpPost(licenseURL); //licenseURL - url , (https://shop.gamma.kz/gs_cart/get_mobile_license) try {//from w ww .ja v a 2 s .c om List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); nameValuePairs.add(new BasicNameValuePair("os", "android")); TelephonyManager telephonyManager = (TelephonyManager) Common.app_ctx .getSystemService(Context.TELEPHONY_SERVICE); nameValuePairs.add(new BasicNameValuePair("imei", telephonyManager.getDeviceId())); nameValuePairs.add(new BasicNameValuePair("code", getLicenseCode())); // , httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { String result = EntityUtils.toString(entity); // result Log.i(TAG, "license = " + result); // boolean b = this.installLicense(result); // Log.i(TAG, "write to file = " + b); } else return false; } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:com.nostra13.example.universalimageloader.HomeActivity.java
private String getMyPhoneNumber() { TelephonyManager mTelephonyMgr;// ww w .ja v a 2s . c o m mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); return mTelephonyMgr.getLine1Number(); }
From source file:totalcross.android.ConnectionManager4A.java
public static void setDefaultConfiguration(int type, String cfg) { if (cfg == null) cfg = ""; switch (type) { case GPRS: {// w w w. j a v a 2s . c o m int id = -1; ContentResolver contentResolver = Launcher4A.loader.getContentResolver(); Cursor cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" }, "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null); if (cursor == null || cursor.getCount() <= 0) { TelephonyManager tel = (TelephonyManager) Launcher4A.loader .getSystemService(Context.TELEPHONY_SERVICE); String networkOperator = tel.getNetworkOperator(); if (networkOperator != null && networkOperator.length() > 0) { int mcc = Integer.parseInt(networkOperator.substring(0, 3)); int mnc = Integer.parseInt(networkOperator.substring(3)); ContentValues values = new ContentValues(); values.put("apn", "tim.br"); values.put("user", "tim"); values.put("password", "tim"); values.put("mcc", mcc); values.put("mnc", mnc); values.put("numeric", mcc + "" + mnc); contentResolver.insert(CONTENT_URI, values); cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" }, "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null); } } if (cursor == null) return; if (cursor.moveToFirst()) id = cursor.getInt(0); cursor.close(); if (id > -1) { ContentValues values = new ContentValues(); //See /etc/apns-conf.xml. The TelephonyProvider uses this file to provide //content://telephony/carriers/preferapn URI mapping values.put("apn_id", id); contentResolver.update(PREFERRED_APN_URI, values, null, null); cursor = contentResolver.query(PREFERRED_APN_URI, new String[] { "name", "apn" }, "_id=" + id, null, null); if (cursor != null) cursor.close(); } } break; case WIFI: connWIFI = connWIFIPrefix + cfg; break; //default: // throw new IllegalArgumentException("Invalid value for argument 'type'"); } }
From source file:com.karpenstein.signalmon.NetServerService.java
@Override public void onCreate() { super.onCreate(); try {// ww w. j a va 2s. c o m jsonState = new JSONObject(); jsonState.put("dataActivity", TelephonyManager.DATA_ACTIVITY_NONE); } catch (JSONException ex) { Log.d("NetServerService", "Failed to put data activity in the JSONObject"); } // Get the telephony manager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null) Log.d("NetServerService", "TelephonyManager was null."); Log.d("NetServerService", "about to create PhoneStateListener"); // Create a new PhoneStateListener psListener = new PhoneStateListener() { @Override public void onDataActivity(int direction) { Log.d("NetServerService", "received onDataActivity message"); try { jsonState.put("dataActivity", direction); } catch (JSONException ex) { } notifyListeners(); } @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { Log.d("NetServerService", "received onSignalStrength message"); try { jsonState.put("cdmaDbm", signalStrength.getCdmaDbm()); jsonState.put("cdmaEcio", signalStrength.getCdmaEcio()); jsonState.put("evdoDbm", signalStrength.getEvdoDbm()); jsonState.put("evdoEcio", signalStrength.getEvdoEcio()); jsonState.put("evdoSnr", signalStrength.getEvdoSnr()); jsonState.put("gsmBitErrorRate", signalStrength.getGsmBitErrorRate()); jsonState.put("gsmSignalStrength", signalStrength.getGsmSignalStrength()); jsonState.put("isGsm", signalStrength.isGsm()); } catch (JSONException ex) { } notifyListeners(); } @Override public void onDataConnectionStateChanged(int state, int networkType) { Log.d("NetServerService", "received onDataConnectionStateChanged message"); try { jsonState.put("connState", state); jsonState.put("netType", networkType); } catch (JSONException ex) { } notifyListeners(); } }; Log.d("NetServerService", "about to call telephonyManager.listen"); // Register the listener with the telephony manager telephonyManager.listen(psListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_DATA_ACTIVITY); Log.d("NetServerService", "done calling telephonyManager.listen -- exiting onCreate"); }
From source file:com.polyvi.xface.extension.devicecapability.XDeviceCapabilityExt.java
/** * ?device?(IMSI)//from ww w . j av a 2s . c o m * * @param context * @return */ private String getImsi(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return XStringUtils.isEmptyString(tm.getSubscriberId()) ? "" : tm.getSubscriberId(); }
From source file:com.commonsware.cwac.locpoll.demo.LocationReceiver.java
@Override public void onReceive(Context context, Intent intent) { mContext = context;//from w w w .j a va 2s . c o 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:com.urremote.classifier.common.ExceptionHandler.java
private static String getIMEI(final Context context) { return ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); }
From source file:com.snt.bt.recon.activities.MyPreferencesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit(); mContext = this; //For Device ID telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); }
From source file:org.ubicompforall.BusTUC.Speech.HTTP.java
public CBRAnswer blackList(double lat, double lon, String prevGuess, Context context) { HttpClient client = new DefaultHttpClient(); String response = ""; CBRAnswer answ = null;// w w w . j ava 2 s . c om Calculate calc = null; try { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String t_id = tm.getDeviceId(); String tmp = "TABuss"; String p_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); HttpGet httpget = new HttpGet( "http://vm-6114.idi.ntnu.no:1337/SpeechServer/cbrGuess?lat=" + lat + "&lon=" + lon + "&devID=" + tmp + p_id + "&dest=" + URLEncoder.encode(prevGuess, "UTF-8") + "&blacklist=true"); long first = System.nanoTime(); response = EntityUtils.toString(client.execute(httpget).getEntity(), "UTF-8"); calc = new Calculate(); System.out.println("RESPONSE: " + response); answ = calc.createCBRAnswer(response); } catch (Exception e) { e.printStackTrace(); } return answ; }