Skip to content

Commit

Permalink
updated Android project to match iOS functions (always SIM data)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-François Puissant committed Mar 5, 2018
1 parent f853bc1 commit 14ae59b
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String getName() {

@ReactMethod
public void carrierName(Promise promise) {
String carrierName = mTelephonyManager.getNetworkOperatorName();
String carrierName = mTelephonyManager.getSimOperatorName();
if (carrierName != null) {
promise.resolve(carrierName);
} else {
Expand All @@ -39,40 +39,42 @@ public void carrierName(Promise promise) {

@ReactMethod
public void isoCountryCode(Promise promise) {
String iso = mTelephonyManager.getNetworkCountryIso();
String iso = mTelephonyManager.getSimCountryIso();
if (iso != null) {
promise.resolve(iso);
} else {
promise.reject(E_NO_ISO_COUNTRY_CODE, "No iso country code");
}
}

// returns MCC (3 digits)
@ReactMethod
public void mobileCountryCode(Promise promise) {
String mcc = mTelephonyManager.getNetworkOperator();
if (mcc != null) {
promise.resolve(mcc);
String plmn = mTelephonyManager.getSimOperator();
if (plmn != null) {
promise.resolve(plmn.substring(0, 3));
} else {
promise.reject(E_NO_MOBILE_COUNTRY_CODE, "No mobile country code");
}
}

// returns MNC (2 or 3 digits)
@ReactMethod
public void mobileNetworkCode(Promise promise) {
String mnc = mTelephonyManager.getNetworkOperator();
if (mnc != null) {
promise.resolve(mnc);
String plmn = mTelephonyManager.getSimOperator();
if (plmn != null) {
promise.resolve(plmn.substring(3));
} else {
promise.reject(E_NO_MOBILE_NETWORK, "No mobile network code");
}
}

// return MCC + MNC, e.g. 46697
// return MCC + MNC (5 or 6 digits), e.g. 20601
@ReactMethod
public void mobileNetworkOperator(Promise promise) {
String operator = mTelephonyManager.getNetworkOperator();
if (operator != null) {
promise.resolve(operator);
String plmn = mTelephonyManager.getSimOperator();
if (plmn != null) {
promise.resolve(plmn);
} else {
promise.reject(E_NO_NETWORK_OPERATOR, "No mobile network operator");
}
Expand Down

0 comments on commit 14ae59b

Please sign in to comment.