List of usage examples for android.telephony TelephonyManager getNetworkOperatorName
public String getNetworkOperatorName()
From source file:com.onesignal.OSUtils.java
String getCarrierName() { TelephonyManager manager = (TelephonyManager) OneSignal.appContext .getSystemService(Context.TELEPHONY_SERVICE); String carrierName = manager.getNetworkOperatorName(); return "".equals(carrierName) ? null : carrierName; }
From source file:com.androchill.call411.MainActivity.java
private Phone getHardwareSpecs() { ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); PhoneBuilder pb = new PhoneBuilder(); pb.setModelNumber(Build.MODEL);/* w w w . ja v a 2s . co m*/ pb.setManufacturer(Build.MANUFACTURER); Process p = null; String board_platform = "No data available"; try { p = new ProcessBuilder("/system/bin/getprop", "ro.chipname").redirectErrorStream(true).start(); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = br.readLine()) != null) { board_platform = line; } p.destroy(); } catch (IOException e) { e.printStackTrace(); board_platform = "No data available"; } pb.setProcessor(board_platform); ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(mInfo); pb.setRam((int) (mInfo.totalMem / 1048576L)); pb.setBatteryCapacity(getBatteryCapacity()); pb.setTalkTime(-1); pb.setDimensions("No data available"); WindowManager mWindowManager = getWindowManager(); Display mDisplay = mWindowManager.getDefaultDisplay(); Point mPoint = new Point(); mDisplay.getSize(mPoint); pb.setScreenResolution(mPoint.x + " x " + mPoint.y + " pixels"); DisplayMetrics mDisplayMetrics = new DisplayMetrics(); mDisplay.getMetrics(mDisplayMetrics); int mDensity = mDisplayMetrics.densityDpi; pb.setScreenSize( Math.sqrt(Math.pow(mPoint.x / (double) mDensity, 2) + Math.pow(mPoint.y / (double) mDensity, 2))); Camera camera = Camera.open(0); android.hardware.Camera.Parameters params = camera.getParameters(); List sizes = params.getSupportedPictureSizes(); Camera.Size result = null; ArrayList<Integer> arrayListForWidth = new ArrayList<Integer>(); ArrayList<Integer> arrayListForHeight = new ArrayList<Integer>(); for (int i = 0; i < sizes.size(); i++) { result = (Camera.Size) sizes.get(i); arrayListForWidth.add(result.width); arrayListForHeight.add(result.height); } if (arrayListForWidth.size() != 0 && arrayListForHeight.size() != 0) { pb.setCameraMegapixels( Collections.max(arrayListForHeight) * Collections.max(arrayListForWidth) / (double) 1000000); } else { pb.setCameraMegapixels(-1); } camera.release(); pb.setPrice(-1); pb.setWeight(-1); pb.setSystem("Android " + Build.VERSION.RELEASE); StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); StatFs statInternal = new StatFs(Environment.getRootDirectory().getAbsolutePath()); double storageSize = ((stat.getBlockSizeLong() * stat.getBlockCountLong()) + (statInternal.getBlockSizeLong() * statInternal.getBlockCountLong())) / 1073741824L; pb.setStorageOptions(storageSize + " GB"); TelephonyManager telephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)); String operatorName = telephonyManager.getNetworkOperatorName(); if (operatorName.length() == 0) operatorName = "No data available"; pb.setCarrier(operatorName); pb.setNetworkFrequencies("No data available"); pb.setImage(null); return pb.createPhone(); }
From source file:com.odo.kcl.mobileminer.miner.MinerService.java
private void connectivityChanged() { String name = "None"; ConnectivityManager manager = (ConnectivityManager) getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = manager.getActiveNetworkInfo(); if (netInfo != null) { if (netInfo.getState() == NetworkInfo.State.CONNECTED) { switch (netInfo.getType()) { case ConnectivityManager.TYPE_WIFI: wifiData = true;/*from www . j a v a2s . c o m*/ mobileData = false; if (!updating) startUpdating(); WifiManager wifiMgr = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); name = wifiInfo.getSSID(); if (!networkName.equals(name)) { wirelessData = new WifiData(wifiInfo); MinerData helper = new MinerData(context); helper.putWifiNetwork(helper.getWritableDatabase(), wirelessData, new Date()); helper.close(); networkName = name; networkBroadcast(); } startScan(); // Always scan when we've got WIFI. //Log.i("MinerService","CONNECTED: WIFI"); break; case ConnectivityManager.TYPE_MOBILE: wifiData = false; mobileData = true; if ("goldfish".equals(Build.HARDWARE)) { if (!updating) startUpdating(); } else { updating = false; } // https://code.google.com/p/android/issues/detail?id=24227 //String name; Cursor c; //c = this.getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"), null, null, null, null); //name = c.getString(c.getColumnIndex("name")); TelephonyManager telephonyManager = ((TelephonyManager) this .getSystemService(Context.TELEPHONY_SERVICE)); name = telephonyManager.getNetworkOperatorName(); if (!networkName.equals(name)) { MinerData helper = new MinerData(context); helper.putMobileNetwork(helper.getWritableDatabase(), telephonyManager, new Date()); helper.close(); networkName = name; networkBroadcast(); } //startScan(); //Log.i("MinerService","CONNECTED MOBILE: "+name); break; default: //Log.i("MinerService",netInfo.getTypeName()); break; } } else { scanning = false; } } else { scanning = false; networkName = "null"; } }
From source file:android_network.hetnet.vpn_service.Util.java
public static String getGeneralInfo(Context context) { StringBuilder sb = new StringBuilder(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); sb.append(String.format("Interactive %B\r\n", isInteractive(context))); sb.append(String.format("Connected %B\r\n", isConnected(context))); sb.append(String.format("WiFi %B\r\n", isWifiActive(context))); sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context))); sb.append(String.format("Roaming %B\r\n", isRoaming(context))); if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(), tm.getSimOperator()));/*from www.ja va2s . c om*/ if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(), tm.getNetworkOperator())); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context))); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) sb.append(String.format("Data saving %B\r\n", dataSaving(context))); if (sb.length() > 2) sb.setLength(sb.length() - 2); return sb.toString(); }
From source file:com.yozio.android.YozioHelper.java
private void setCarrierMobileAndDeviceInfo() { SharedPreferences settings = context.getSharedPreferences("yozioPreferences", 0); try {//from www. j a v a2 s . c o m TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); carrierName = telephonyManager.getNetworkOperatorName(); carrierCountryCode = telephonyManager.getNetworkCountryIso(); if (telephonyManager.getNetworkOperator() != null && (telephonyManager.getNetworkOperator().length() == 5 || telephonyManager.getNetworkOperator().length() == 6)) { mobileCountryCode = telephonyManager.getNetworkOperator().substring(0, 3); mobileNetworkCode = telephonyManager.getNetworkOperator().substring(3); } deviceId = telephonyManager.getDeviceId(); if (!isValidDeviceId(deviceId)) { // Fetch the emulator device ID from the preferences deviceId = settings.getString("emulatorDeviceId", null); } if (!isValidDeviceId(deviceId)) { StringBuffer buff = new StringBuffer(); buff.append("emulator"); String chars = "1234567890abcdefghijklmnopqrstuvw"; int ccLength = chars.length() - 1; for (int i = 0; i < 32; i++) { int index = (int) (Math.random() * ccLength); buff.append(chars.charAt(index)); } SharedPreferences.Editor editor = settings.edit(); editor.putString("emulatorDeviceId", deviceId); editor.commit(); deviceId = buff.toString(); } deviceId = deviceId.toLowerCase(); } catch (Exception e) { deviceId = null; } }
From source file:com.softcoil.ApnDefaults.java
/** * This method provides a means for clients to report new, good APN connection parameters * to a central repository so that they can be integrated with this class and shared with * the public.//from www. j a va 2 s. c om * * It contains protections so that new ApnParameters are only reported to the server the first * time this method is called. In addition, it uses a short connection timeout so it can be * safely called from your current worker thread without worry that it will unnecessarily * delay your process. * * It should be called immediately after successfully sending a MMS message. Example:<br/> * <pre> * //Send your MMS using whatever method you currently use. * byte[] response = myMmsHttpPost(mmscUrl, mmsProxy, mmsProxyPort, sendReqPdu); * * //Parse the response. * SendConf sendConf = (SendConf) new PduParser(response).parse(); * * //Check to see if the response was success. * if(sendConf != null && sendConf.getResponseStatus() == PduHeaders.RESPONSE_STATUS_OK) { * //Report the ApnParameters used for the post. * ApnParameters parameters = new ApnParameters(mmscUrl, mmsProxy, mmsProxyPort); * ApnDefaults.reportApnData(context, parameters); * } * * //Continue your process. * ... * </pre> * * In order for this class to be useful we must collect data from as many working * configurations as possible. Adding a call to this method after a successful MMSC operation * in your app will help us all to provide a good MMS experience to our users. * * @param context The current context. * @param apnParameters The known good ApnParameters to report. */ public static void reportApnData(Context context, ApnParameters apnParameters) { if (apnParameters == null) return; String apnData = apnParameters.getMmscUrl() + "|" + apnParameters.getProxyAddress() + "|" + apnParameters.getProxyPort(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String previousApnData = prefs.getString(PREF_KEY_LAST_APN_REPORT, null); if (!apnData.equals(previousApnData)) { //Save new apn data prefs.edit().putString(PREF_KEY_LAST_APN_REPORT, apnData).apply(); //Report new apn data TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String networkOperator = tm.getNetworkOperator(); String networkOperatorName = tm.getNetworkOperatorName(); String simOperator = tm.getSimOperator(); String simOperatorName = tm.getSimOperatorName(); //Create HttpClient AndroidHttpClient client = AndroidHttpClient.newInstance("ApnDefaults/0.1"); HttpParams params = client.getParams(); HttpProtocolParams.setContentCharset(params, "UTF-8"); HttpConnectionParams.setConnectionTimeout(params, 1 * 1000); //Set timeout to wait for a connection. HttpConnectionParams.setSoTimeout(params, 1 * 1000); //Set timeout to wait for a response. try { StringBuffer uriString = new StringBuffer(REPORT_URL).append("?") //Report the MMSC connection used. .append("apnData=").append(URLEncoder.encode(apnData, "UTF-8")) //SIM and Network data are reported to enable determining which //parameters work under which circumstances. .append("&simOperator=").append(URLEncoder.encode(simOperator, "UTF-8")) .append("&simOperatorName=").append(URLEncoder.encode(simOperatorName, "UTF-8")) .append("&simCountry=").append(URLEncoder.encode(tm.getSimCountryIso(), "UTF-8")) .append("&networkOperator=").append(URLEncoder.encode(networkOperator, "UTF-8")) .append("&networkOperatorName=").append(URLEncoder.encode(networkOperatorName, "UTF-8")) .append("&networkCountry=").append(URLEncoder.encode(tm.getNetworkCountryIso(), "UTF-8")); URI uri = new URI(uriString.toString()); //Send request client.execute(new HttpGet(uri)); client.close(); } catch (Exception e) { } } }
From source file:com.softcoil.ApnDefaults.java
/** * Get the default ApnParameters for the current carrier from the APN_PARAMETERS_MAP. This uses * a combination of SIM MCCMNC, SIM operator name, network MCCMNC, and network name to try to * determine the correct parameters to use. * * If there is no match and fallback is true the method will attempt to return a match on the * SIM MCCMNC only. This will help in many cases but will return incorrect parameters in others. * * @param context The current context./*from ww w. j a va2 s .c o m*/ * @param fallBack Should we attempt to fallback on matching just the SIM MCCMNC if we don't * find a match for the full key? * @return The ApnParameters or null. */ public static ApnParameters getApnParameters(Context context, boolean fallBack) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); StringBuffer sb = new StringBuffer().append(tm.getSimOperator()).append('|').append(tm.getSimOperatorName()) .append('|').append(tm.getNetworkOperator()).append('|').append(tm.getNetworkOperatorName()); ApnParameters apnParameters = APN_PARAMETERS_MAP.get(sb.toString()); //Fallback on old data if we don't have new full network keys yet. if (apnParameters == null && fallBack) { apnParameters = APN_PARAMETERS_MAP.get(tm.getSimOperator()); } return apnParameters; }
From source file:com.master.metehan.filtereagle.Util.java
public static String getGeneralInfo(Context context) { StringBuilder sb = new StringBuilder(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); sb.append(String.format("Interactive %B\r\n", isInteractive(context))); sb.append(String.format("Connected %B\r\n", isConnected(context))); sb.append(String.format("WiFi %B\r\n", isWifiActive(context))); sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context))); sb.append(String.format("Roaming %B\r\n", isRoaming(context))); sb.append(String.format("Type %s\r\n", getPhoneTypeName(tm.getPhoneType()))); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || !hasPhoneStatePermission(context)) { if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(), tm.getSimOperator())); if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(), tm.getNetworkOperator())); }// w w w . j a v a 2 s. c om PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) sb.append(String.format("Battery optimizing %B\r\n", !pm.isIgnoringBatteryOptimizations(context.getPackageName()))); if (sb.length() > 2) sb.setLength(sb.length() - 2); return sb.toString(); }
From source file:fr.inria.ucn.collectors.NetworkStateCollector.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private JSONObject getMobile(TelephonyManager tm) throws JSONException { JSONObject mob = new JSONObject(); mob.put("call_state", tm.getCallState()); mob.put("data_activity", tm.getDataActivity()); mob.put("network_type", tm.getNetworkType()); mob.put("network_type_str", Helpers.getTelephonyNetworkType(tm.getNetworkType())); mob.put("phone_type", tm.getPhoneType()); mob.put("phone_type_str", Helpers.getTelephonyPhoneType(tm.getPhoneType())); mob.put("sim_state", tm.getSimState()); mob.put("network_country", tm.getNetworkCountryIso()); mob.put("network_operator", tm.getNetworkOperator()); mob.put("network_operator_name", tm.getNetworkOperatorName()); // current cell location CellLocation cl = tm.getCellLocation(); if (cl != null) { JSONObject loc = new JSONObject(); if (cl instanceof GsmCellLocation) { JSONObject cell = new JSONObject(); cell.put("cid", ((GsmCellLocation) cl).getCid()); cell.put("lac", ((GsmCellLocation) cl).getLac()); cell.put("psc", ((GsmCellLocation) cl).getPsc()); loc.put("gsm", cell); } else if (cl instanceof CdmaCellLocation) { JSONObject cell = new JSONObject(); cell.put("bs_id", ((CdmaCellLocation) cl).getBaseStationId()); cell.put("bs_lat", ((CdmaCellLocation) cl).getBaseStationLatitude()); cell.put("bs_lon", ((CdmaCellLocation) cl).getBaseStationLongitude()); cell.put("net_id", ((CdmaCellLocation) cl).getNetworkId()); cell.put("sys_id", ((CdmaCellLocation) cl).getSystemId()); loc.put("cdma", cell); }// w ww. j av a 2 s . c o m mob.put("cell_location", loc); } // Cell neighbors List<NeighboringCellInfo> ncl = tm.getNeighboringCellInfo(); if (ncl != null) { JSONArray cells = new JSONArray(); for (NeighboringCellInfo nc : ncl) { JSONObject jnc = new JSONObject(); jnc.put("cid", nc.getCid()); jnc.put("lac", nc.getLac()); jnc.put("network_type", nc.getNetworkType()); jnc.put("network_type_str", Helpers.getTelephonyNetworkType(nc.getNetworkType())); jnc.put("psc", nc.getPsc()); jnc.put("rssi", nc.getRssi()); cells.put(jnc); } mob.put("neigh_cells", cells); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { // only works for API level >=17 List<CellInfo> aci = (List<CellInfo>) tm.getAllCellInfo(); if (aci != null) { JSONArray cells = new JSONArray(); for (CellInfo ci : aci) { JSONObject jci = new JSONObject(); if (ci instanceof CellInfoGsm) { CellInfoGsm cigsm = (CellInfoGsm) ci; jci.put("is_registered", cigsm.isRegistered()); jci.put("type", "gsm"); jci.put("cid", cigsm.getCellIdentity().getCid()); jci.put("lac", cigsm.getCellIdentity().getLac()); jci.put("mcc", cigsm.getCellIdentity().getMcc()); jci.put("mnc", cigsm.getCellIdentity().getMnc()); jci.put("psc", cigsm.getCellIdentity().getPsc()); jci.put("asu_level", cigsm.getCellSignalStrength().getAsuLevel()); jci.put("level", cigsm.getCellSignalStrength().getLevel()); jci.put("dbm", cigsm.getCellSignalStrength().getDbm()); } else if (ci instanceof CellInfoCdma) { CellInfoCdma cicdma = (CellInfoCdma) ci; jci.put("is_registered", cicdma.isRegistered()); jci.put("type", "cdma"); jci.put("bs_id", cicdma.getCellIdentity().getBasestationId()); jci.put("bs_lat", cicdma.getCellIdentity().getLatitude()); jci.put("bs_lon", cicdma.getCellIdentity().getLongitude()); jci.put("net_id", cicdma.getCellIdentity().getNetworkId()); jci.put("sys_id", cicdma.getCellIdentity().getSystemId()); jci.put("asu_level", cicdma.getCellSignalStrength().getAsuLevel()); jci.put("dbm", cicdma.getCellSignalStrength().getDbm()); jci.put("level", cicdma.getCellSignalStrength().getLevel()); jci.put("cdma_dbm", cicdma.getCellSignalStrength().getCdmaDbm()); jci.put("cdma_ecio", cicdma.getCellSignalStrength().getCdmaEcio()); jci.put("cdma_level", cicdma.getCellSignalStrength().getCdmaLevel()); jci.put("evdo_dbm", cicdma.getCellSignalStrength().getEvdoDbm()); jci.put("evdo_ecio", cicdma.getCellSignalStrength().getEvdoEcio()); jci.put("evdo_level", cicdma.getCellSignalStrength().getEvdoLevel()); jci.put("evdo_snr", cicdma.getCellSignalStrength().getEvdoSnr()); } else if (ci instanceof CellInfoWcdma) { CellInfoWcdma ciwcdma = (CellInfoWcdma) ci; jci.put("is_registered", ciwcdma.isRegistered()); jci.put("type", "wcdma"); jci.put("cid", ciwcdma.getCellIdentity().getCid()); jci.put("lac", ciwcdma.getCellIdentity().getLac()); jci.put("mcc", ciwcdma.getCellIdentity().getMcc()); jci.put("mnc", ciwcdma.getCellIdentity().getMnc()); jci.put("psc", ciwcdma.getCellIdentity().getPsc()); jci.put("asu_level", ciwcdma.getCellSignalStrength().getAsuLevel()); jci.put("dbm", ciwcdma.getCellSignalStrength().getDbm()); jci.put("level", ciwcdma.getCellSignalStrength().getLevel()); } else if (ci instanceof CellInfoLte) { CellInfoLte cilte = (CellInfoLte) ci; jci.put("is_registered", cilte.isRegistered()); jci.put("type", "lte"); jci.put("ci", cilte.getCellIdentity().getCi()); jci.put("mcc", cilte.getCellIdentity().getMcc()); jci.put("mnc", cilte.getCellIdentity().getMnc()); jci.put("pci", cilte.getCellIdentity().getPci()); jci.put("tac", cilte.getCellIdentity().getTac()); jci.put("asu_level", cilte.getCellSignalStrength().getAsuLevel()); jci.put("dbm", cilte.getCellSignalStrength().getDbm()); jci.put("level", cilte.getCellSignalStrength().getLevel()); jci.put("timing_adv", cilte.getCellSignalStrength().getTimingAdvance()); } cells.put(jci); } mob.put("all_cells", cells); } } return mob; }
From source file:pandroid.agent.PandroidAgentListener.java
/** * Retrieve currently registered network operator, i.e. vodafone, movistar, etc... */// w w w.ja va2 s. co m private void getNetworkOperator() { String networkOperator = Core.defaultNetworkOperator; String serviceName = Context.TELEPHONY_SERVICE; TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext() .getSystemService(serviceName); networkOperator = telephonyManager.getNetworkOperatorName(); if (networkOperator != null) putSharedData("PANDROID_DATA", "networkOperator", networkOperator, "string"); }