List of usage examples for android.telephony TelephonyManager getSimOperator
public String getSimOperator()
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())); 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);//from w w w .j a v a 2s .co m return sb.toString(); }
From source file:com.samknows.measurement.AppSettings.java
public Map<String, String> getJSONExtra() { Map<String, String> ret = new HashMap<String, String>(); if (!anonymous) { ret.put(JSON_UNIT_ID, getUnitId()); }/*www . j a va 2s .c o m*/ ret.put(JSON_APP_VERSION_NAME, app_version_name); ret.put(JSON_APP_VERSION_CODE, app_version_code); ScheduleConfig config = CachingStorage.getInstance().loadScheduleConfig(); if (config != null) { ret.put(JSON_SCHEDULE_CONFIG_VERSION, config.version); } else { ret.put(JSON_SCHEDULE_CONFIG_VERSION, "no_schedule_config"); } long time = System.currentTimeMillis(); ret.put(JSON_TIMESTAMP, (time / 1000) + ""); ret.put(JSON_DATETIME, new java.util.Date(time).toString()); ret.put(JSON_TIMEZONE, TimeUtils.millisToHours(TimeZone.getDefault().getRawOffset()) + ""); if (enterprise_id != null) { ret.put(JSON_ENTERPRISE_ID, enterprise_id); } String user_self_id = PreferenceManager.getDefaultSharedPreferences(ctx) .getString(Constants.PREF_USER_SELF_ID, null); if (user_self_id != null) { ret.put(JSON_USER_SELF_ID, user_self_id); } TelephonyManager manager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); String simOperatorCode = ""; if (manager != null) { simOperatorCode = manager.getSimOperator(); } ret.put(JSON_SIMOPERATORCODE, simOperatorCode); return ret; }
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 www . j ava2s .co 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())); }//from w w w . ja va 2s. co m 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: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.// w w w . java2s. c o m * * 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) { } } }