|
3 | 3 | import java.util.HashMap; |
4 | 4 | import java.util.Locale; |
5 | 5 | import java.util.Map; |
| 6 | +import java.util.List; |
6 | 7 | import java.util.TimeZone; |
7 | 8 |
|
| 9 | +import android.os.Build; |
| 10 | +import android.Manifest; |
| 11 | +import android.content.Intent; |
| 12 | +import android.content.Context; |
| 13 | +import android.content.pm.PackageManager; |
| 14 | +import android.telephony.TelephonyManager; |
| 15 | +import android.telephony.SubscriptionInfo; |
| 16 | +import android.telephony.SubscriptionManager; |
| 17 | + |
| 18 | +import com.facebook.react.bridge.Arguments; |
| 19 | +import com.facebook.react.bridge.NativeModule; |
| 20 | +import com.facebook.react.bridge.ReactContext; |
8 | 21 | import com.facebook.react.bridge.ReactApplicationContext; |
9 | 22 | import com.facebook.react.bridge.ReactContextBaseJavaModule; |
10 | 23 |
|
@@ -39,49 +52,41 @@ public String getName() { |
39 | 52 | int activeSubscriptionInfoCountMax = 0; |
40 | 53 |
|
41 | 54 | try { |
42 | | - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { |
43 | | - if (simPermissionGranted(Manifest.permission.READ_PHONE_STATE)) { |
44 | | - phoneCount = manager.getPhoneCount(); |
45 | | - SubscriptionManager manager = (SubscriptionManager) cntx.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
46 | | - activeSubscriptionInfoCount = manager.getActiveSubscriptionInfoCount(); |
47 | | - activeSubscriptionInfoCountMax = manager.getActiveSubscriptionInfoCountMax(); |
48 | | - |
49 | | - List<SubscriptionInfo> subscriptionInfos = manager.getActiveSubscriptionInfoList(); |
50 | | - int sub = 1; |
51 | | - for (SubscriptionInfo subInfo : subscriptionInfos) { |
52 | | - sub++; |
53 | | - CharSequence carrierName = subInfo.getCarrierName(); |
54 | | - String countryIso = subInfo.getCountryIso(); |
55 | | - int dataRoaming = subInfo.getDataRoaming(); // 1 is enabled ; 0 is disabled |
56 | | - CharSequence displayName = subInfo.getDisplayName(); |
57 | | - String iccId = subInfo.getIccId(); |
58 | | - int mcc = subInfo.getMcc(); |
59 | | - int mnc = subInfo.getMnc(); |
60 | | - String number = subInfo.getNumber(); |
61 | | - int simSlotIndex = subInfo.getSimSlotIndex(); |
62 | | - int subscriptionId = subInfo.getSubscriptionId(); |
63 | | - boolean networkRoaming = telManager.isNetworkRoaming(simSlotIndex); |
64 | | - String deviceId = telManager.getDeviceId(simSlotIndex); |
65 | | - |
66 | | - constants.put("carrierName" + sub, carrierName.toString()); |
67 | | - constants.put("displayName" + sub, displayName.toString()); |
68 | | - constants.put("countryCode" + sub, countryIso); |
69 | | - constants.put("mcc" + sub, mcc); |
70 | | - constants.put("mnc" + sub, mnc); |
71 | | - constants.put("isNetworkRoaming" + sub, networkRoaming); |
72 | | - constants.put("isDataRoaming" + sub, (dataRoaming == 1)); |
73 | | - constants.put("simSlotIndex" + sub, simSlotIndex); |
74 | | - constants.put("phoneNumber" + sub, number); |
75 | | - constants.put("deviceId" + sub, deviceId); |
76 | | - constants.put("simSerialNumber" + sub, iccId); |
77 | | - constants.put("subscriptionId" + sub, subscriptionId); |
78 | | - |
79 | | - sims.put(simData); |
80 | | - } |
81 | | - } |
| 55 | + SubscriptionManager manager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 56 | + phoneCount = manager.getPhoneCount(); |
| 57 | + activeSubscriptionInfoCount = manager.getActiveSubscriptionInfoCount(); |
| 58 | + activeSubscriptionInfoCountMax = manager.getActiveSubscriptionInfoCountMax(); |
| 59 | + |
| 60 | + List<SubscriptionInfo> subscriptionInfos = manager.getActiveSubscriptionInfoList(); |
| 61 | + int sub = 1; |
| 62 | + for (SubscriptionInfo subInfo : subscriptionInfos) { |
| 63 | + sub++; |
| 64 | + CharSequence carrierName = subInfo.getCarrierName(); |
| 65 | + String countryIso = subInfo.getCountryIso(); |
| 66 | + int dataRoaming = subInfo.getDataRoaming(); // 1 is enabled ; 0 is disabled |
| 67 | + CharSequence displayName = subInfo.getDisplayName(); |
| 68 | + String iccId = subInfo.getIccId(); |
| 69 | + int mcc = subInfo.getMcc(); |
| 70 | + int mnc = subInfo.getMnc(); |
| 71 | + String number = subInfo.getNumber(); |
| 72 | + int simSlotIndex = subInfo.getSimSlotIndex(); |
| 73 | + int subscriptionId = subInfo.getSubscriptionId(); |
| 74 | + boolean networkRoaming = telManager.isNetworkRoaming(simSlotIndex); |
| 75 | + String deviceId = telManager.getDeviceId(simSlotIndex); |
| 76 | + |
| 77 | + constants.put("carrierName" + sub, carrierName.toString()); |
| 78 | + constants.put("displayName" + sub, displayName.toString()); |
| 79 | + constants.put("countryCode" + sub, countryIso); |
| 80 | + constants.put("mcc" + sub, mcc); |
| 81 | + constants.put("mnc" + sub, mnc); |
| 82 | + constants.put("isNetworkRoaming" + sub, networkRoaming); |
| 83 | + constants.put("isDataRoaming" + sub, (dataRoaming == 1)); |
| 84 | + constants.put("simSlotIndex" + sub, simSlotIndex); |
| 85 | + constants.put("phoneNumber" + sub, number); |
| 86 | + constants.put("deviceId" + sub, deviceId); |
| 87 | + constants.put("simSerialNumber" + sub, iccId); |
| 88 | + constants.put("subscriptionId" + sub, subscriptionId); |
82 | 89 | } |
83 | | - } catch (JSONException e) { |
84 | | - e.printStackTrace(); |
85 | 90 | } catch (Exception e) { |
86 | 91 | e.printStackTrace(); |
87 | 92 | } |
|
0 commit comments