Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit afa12d6

Browse files
author
markgrin
committed
Realtime get iccid method
1 parent 970173c commit afa12d6

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ RNSimData.getCountryCode()
4949
NOTE: React Native "Modules", when having only constants, work with getters, and the result of `getSimInfo()` is
5050
undefined, you need to access the properties to get any info
5151

52+
### Realtime methods
53+
These methods query SimInfo and callback with result.
54+
```
55+
RNSimData.getRealtimeIccid(iccids => {
56+
if (!iccids)
57+
console.log('get iccids call failed');
58+
for (i in iccids)
59+
console.log(iccids[i]);
60+
})
61+
```
62+
5263
### Caveats
5364

5465
Might crash if tries to use in a phone without any SIM cards.

android/src/main/java/eu/sigrlami/rnsimdata/RNSimDataModule.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.HashMap;
44
import java.util.Map;
55
import java.util.List;
6+
import java.util.LinkedList;
7+
import java.util.ArrayList;
68

79
import android.content.Context;
810
import android.telephony.TelephonyManager;
@@ -13,6 +15,7 @@
1315
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1416
import com.facebook.react.bridge.ReactMethod;
1517
import com.facebook.react.bridge.Callback;
18+
import com.facebook.react.bridge.WritableNativeArray;
1619

1720
public class RNSimDataModule extends ReactContextBaseJavaModule {
1821

@@ -28,6 +31,26 @@ public String getName() {
2831
return "RNSimDataModule";
2932
}
3033

34+
@ReactMethod
35+
public void getRealtimeIccid(Callback callback) {
36+
try {
37+
TelephonyManager telManager = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE);
38+
WritableNativeArray result = new WritableNativeArray();
39+
40+
SubscriptionManager manager = (SubscriptionManager) this.reactContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
41+
List<SubscriptionInfo> subscriptionInfos = manager.getActiveSubscriptionInfoList();
42+
for (SubscriptionInfo subInfo : subscriptionInfos) {
43+
String iccId = subInfo.getIccId();
44+
result.pushString(iccId);
45+
}
46+
callback.invoke(result);
47+
} catch (Exception e) {
48+
e.printStackTrace();
49+
callback.invoke(new String(""));
50+
}
51+
}
52+
53+
3154
@Override
3255
public Map<String, Object> getConstants() {
3356

@@ -75,4 +98,4 @@ public Map<String, Object> getConstants() {
7598

7699
return constants;
77100
}
78-
}
101+
}

index.js

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)