List of usage examples for android.telephony TelephonyManager getPhoneType
public int getPhoneType()
From source file:com.github.nutomic.pegasus.LocationService.java
/** * Register CellListener and show Notification. *//*www . ja v a 2 s . c om*/ @Override public void onCreate() { super.onCreate(); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mCellListener = new CellListener(tm.getPhoneType()); tm.listen(mCellListener, PhoneStateListener.LISTEN_CELL_LOCATION); // Force update. mCellListener.onCellLocationChanged(tm.getCellLocation()); }
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. java 2s.com 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:org.pixmob.droidlink.ui.EventDetailsFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); // Include actions for calling and writing SMS only for phones. final TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); final boolean deviceIsPhone = tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE; if (deviceIsPhone) { menu.add(NONE, R.string.call, NONE, R.string.call).setIcon(R.drawable.ic_menu_call) .setShowAsAction(SHOW_AS_ACTION_ALWAYS); menu.add(NONE, R.string.compose_sms, NONE, R.string.compose_sms).setIcon(R.drawable.ic_menu_compose) .setShowAsAction(SHOW_AS_ACTION_ALWAYS); }/*from w ww.j a v a2 s .c om*/ menu.add(NONE, R.string.delete_event, NONE, R.string.delete_event).setIcon(R.drawable.ic_menu_delete) .setShowAsAction(SHOW_AS_ACTION_IF_ROOM); }
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 w w. j av a2s.co 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:com.wbtech.ums.UmsAgent.java
private static JSONObject getClientDataJSONObject(Context context) { TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displaysMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(displaysMetrics); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); JSONObject clientData = new JSONObject(); try {/*from w w w .j a v a 2 s . co m*/ clientData.put("os_version", CommonUtil.getOsVersion(context)); clientData.put("platform", "android"); clientData.put("language", Locale.getDefault().getLanguage()); clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());// clientData.put("appkey", CommonUtil.getAppKey(context)); clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels); clientData.put("ismobiledevice", true); clientData.put("phonetype", tm.getPhoneType());// clientData.put("imsi", tm.getSubscriberId()); clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context)); clientData.put("time", CommonUtil.getTime()); clientData.put("version", CommonUtil.getVersion(context)); clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context)); SCell sCell = CommonUtil.getCellInfo(context); clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : ""); clientData.put("cellid", sCell != null ? sCell.CID + "" : ""); clientData.put("lac", sCell != null ? sCell.LAC + "" : ""); clientData.put("modulename", Build.PRODUCT); clientData.put("devicename", CommonUtil.getDeviceName()); clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress()); clientData.put("havebt", adapter == null ? false : true); clientData.put("havewifi", CommonUtil.isWiFiActive(context)); clientData.put("havegps", locationManager == null ? false : true); clientData.put("havegravity", CommonUtil.isHaveGravity(context));// LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context, UmsAgent.mUseLocationService); clientData.put("latitude", coordinates.latitude); clientData.put("longitude", coordinates.longitude); CommonUtil.printLog("clientData---------->", clientData.toString()); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return clientData; }
From source file:xj.property.ums.UmsAgent.java
public static JSONObject getClientDataJSONObject(Context context) { TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displaysMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(displaysMetrics); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); JSONObject clientData = new JSONObject(); try {// www .j av a 2 s . co m clientData.put("os_version", CommonUtil.getOsVersion(context)); clientData.put("platform", "android"); clientData.put("language", Locale.getDefault().getLanguage()); clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());// clientData.put("appkey", CommonUtil.getAppKey(context)); clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels); clientData.put("ismobiledevice", true); clientData.put("phonetype", tm.getPhoneType());// clientData.put("imsi", tm.getSubscriberId()); clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context)); clientData.put("time", CommonUtil.getTime()); clientData.put("version", CommonUtil.getVersion(context)); clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context)); SCell sCell = CommonUtil.getCellInfo(context); clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : ""); clientData.put("cellid", sCell != null ? sCell.CID + "" : ""); clientData.put("lac", sCell != null ? sCell.LAC + "" : ""); clientData.put("modulename", Build.PRODUCT); clientData.put("devicename", CommonUtil.getDeviceName()); clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress()); clientData.put("havebt", adapter == null ? false : true); clientData.put("havewifi", CommonUtil.isWiFiActive(context)); clientData.put("havegps", locationManager == null ? false : true); clientData.put("havegravity", CommonUtil.isHaveGravity(context));// LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context, UmsAgent.mUseLocationService); clientData.put("latitude", coordinates.latitude); clientData.put("longitude", coordinates.longitude); CommonUtil.printLog("clientData---------->", clientData.toString()); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return clientData; }
From source file:com.elitise.appv2.Peripheral.java
public boolean isTabletDevice() { TelephonyManager telephony = (TelephonyManager) getApplicationContext() .getSystemService(Context.TELEPHONY_SERVICE); int type = telephony.getPhoneType(); if (type == TelephonyManager.PHONE_TYPE_NONE) { return true; } else {//from ww w. j av a 2 s . co m return false; } }
From source file:pandroid.agent.PandroidAgentListener.java
/** * Retrieve the type of mobile network currently conncected to, i.e. gms, cdma, etc... *///from ww w .jav a 2 s . c o m private void getPhoneType() { String phoneType = Core.defaultPhoneType; TelephonyManager tM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); int pT = tM.getPhoneType(); switch (pT) { case 0: phoneType = "none"; break; case 1: phoneType = "GSM"; break; case 2: phoneType = "CDMA"; break; case 3: phoneType = "SIP"; break; } if (phoneType != null) putSharedData("PANDROID_DATA", "phoneType", phoneType, "string"); }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayNotCompatibleDialog() { // check if displayed in this app run if (showNotCompatibleDialog) { // check if not disabled in preferences boolean showCompatibilityWarningEnabled = MyApplication.getPreferencesProvider() .getShowCompatibilityWarning(); if (showCompatibilityWarningEnabled) { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // check if device contains telephony hardware (some tablets doesn't report even if have) // NOTE: in the future this may need to be expanded when new specific features appear PackageManager packageManager = getPackageManager(); boolean noRadioDetected = !(packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) && (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_GSM) || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA))); // show dialog if something is not supported if (noRadioDetected) { Log.d("displayNotCompatibleDialog(): Not compatible because of radio: %s, phone type: %s", noRadioDetected, telephonyManager.getPhoneType()); //use custom layout to show "don't show this again" checkbox AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View dialogLayout = inflater.inflate(R.layout.dont_show_again_dialog, null); final CheckBox dontShowAgainCheckbox = (CheckBox) dialogLayout .findViewById(R.id.dont_show_again_dialog_checkbox); dialogBuilder.setView(dialogLayout); AlertDialog alertDialog = dialogBuilder.create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.main_dialog_not_compatible_title); StringBuilder stringBuilder = new StringBuilder( getString(R.string.main_dialog_not_compatible_begin)); if (noRadioDetected) { stringBuilder.append(getString(R.string.main_dialog_no_compatible_mobile_radio_message)); }/*from w w w.j a v a2s.c o m*/ // text set this way to prevent checkbox from disappearing when text is too long TextView messageTextView = (TextView) dialogLayout .findViewById(R.id.dont_show_again_dialog_textview); messageTextView.setText(stringBuilder.toString()); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean dontShowAgainCheckboxChecked = dontShowAgainCheckbox.isChecked(); Log.d("displayNotCompatibleDialog(): Don't show again checkbox checked = %s", dontShowAgainCheckboxChecked); if (dontShowAgainCheckboxChecked) { MyApplication.getPreferencesProvider().setShowCompatibilityWarning(false); } } }); alertDialog.show(); } } showNotCompatibleDialog = false; } }
From source file:com.android.bluetooth.map.BluetoothMapContent.java
private void setFilterInfo(FilterInfo fi) { TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); if (tm != null) { fi.phoneType = tm.getPhoneType(); fi.phoneNum = tm.getLine1Number(); fi.phoneAlphaTag = tm.getLine1AlphaTag(); if (D)//from w w w. java2s . c o m Log.d(TAG, "phone type = " + fi.phoneType + " phone num = " + fi.phoneNum + " phone alpha tag = " + fi.phoneAlphaTag); } }