Java Code Examples for android.telephony.SubscriptionInfo#getCarrierName()
The following examples show how to use
android.telephony.SubscriptionInfo#getCarrierName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Phone.java From batteryhub with Apache License 2.0 | 5 votes |
/** * Retrieves network operator names from subscription manager. * NOTE: Requires SDK level 22 or above * * @param context * @return */ private static String getNetworkOperators(Context context) { String operator = ""; if (!PermissionsUtils.checkPermission(context, Manifest.permission.READ_PHONE_STATE)) { return operator; } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { SubscriptionManager subscriptionManager = SubscriptionManager.from(context); if (subscriptionManager != null) { List<SubscriptionInfo> subscriptions = subscriptionManager.getActiveSubscriptionInfoList(); if (subscriptions != null) { for (SubscriptionInfo info : subscriptions) { CharSequence carrierName = info.getCarrierName(); if (carrierName != null && carrierName.length() > 0) { operator += carrierName + ";"; } } // Remove last delimiter if (operator.length() >= 1) { operator = operator.substring(0, operator.length() - 1); } } } } return operator; }
Example 2
Source File: RNSimDataModule.java From react-native-sim-data with MIT License | 4 votes |
@Override public Map<String, Object> getConstants() { final Map<String, Object> constants = new HashMap<>(); try { TelephonyManager telManager = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE); SubscriptionManager manager = (SubscriptionManager) this.reactContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); List<SubscriptionInfo> subscriptionInfos = manager.getActiveSubscriptionInfoList(); int sub = 0; for (SubscriptionInfo subInfo : subscriptionInfos) { CharSequence carrierName = subInfo.getCarrierName(); String countryIso = subInfo.getCountryIso(); int dataRoaming = subInfo.getDataRoaming(); // 1 is enabled ; 0 is disabled CharSequence displayName = subInfo.getDisplayName(); String iccId = subInfo.getIccId(); int mcc = subInfo.getMcc(); int mnc = subInfo.getMnc(); String number = subInfo.getNumber(); int simSlotIndex = subInfo.getSimSlotIndex(); int subscriptionId = subInfo.getSubscriptionId(); boolean networkRoaming = telManager.isNetworkRoaming(); String deviceId = telManager.getDeviceId(simSlotIndex); //String deviceId = telManager.getImei(simSlotIndex) || telManager.getMeid(simSlotIndex); constants.put("carrierName" + sub, carrierName.toString()); constants.put("displayName" + sub, displayName.toString()); constants.put("countryCode" + sub, countryIso); constants.put("mcc" + sub, mcc); constants.put("mnc" + sub, mnc); constants.put("isNetworkRoaming" + sub, networkRoaming); constants.put("isDataRoaming" + sub, (dataRoaming == 1)); constants.put("simSlotIndex" + sub, simSlotIndex); constants.put("phoneNumber" + sub, number); constants.put("deviceId" + sub, deviceId); constants.put("simSerialNumber" + sub, iccId); constants.put("subscriptionId" + sub, subscriptionId); sub++; } } catch (Exception e) { e.printStackTrace(); } return constants; }