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

Realtime get iccid method #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ RNSimData.getCountryCode()
NOTE: React Native "Modules", when having only constants, work with getters, and the result of `getSimInfo()` is
undefined, you need to access the properties to get any info

### Realtime methods
These methods query SimInfo and callback with result.
```
RNSimData.getRealtimeIccid(iccids => {
if (!iccids)
console.log('get iccids call failed');
for (i in iccids)
console.log(iccids[i]);
})
```

### Caveats

Might crash if tries to use in a phone without any SIM cards.
Expand Down
40 changes: 39 additions & 1 deletion android/src/main/java/eu/sigrlami/rnsimdata/RNSimDataModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.LinkedList;
import java.util.ArrayList;

import android.content.Context;
import android.telephony.TelephonyManager;
Expand All @@ -13,6 +15,8 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;

public class RNSimDataModule extends ReactContextBaseJavaModule {

Expand All @@ -28,6 +32,40 @@ public String getName() {
return "RNSimDataModule";
}

@ReactMethod
public void getRealtimeInfo(Callback callback) {
try {
TelephonyManager telManager = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE);
WritableNativeArray result = new WritableNativeArray();

SubscriptionManager manager = (SubscriptionManager) this.reactContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subscriptionInfos = manager.getActiveSubscriptionInfoList();
for (SubscriptionInfo subInfo : subscriptionInfos) {
String iccId = subInfo.getIccId();
int mcc = subInfo.getMcc();
int mnc = subInfo.getMnc();
int simSlotIndex = subInfo.getSimSlotIndex();
CharSequence carrierName = subInfo.getCarrierName();
String networkCountry = telManager.getNetworkCountryIso();

WritableNativeMap map = new WritableNativeMap();

map.putString("iccid", iccId);
map.putString("mcc", Integer.toString(mcc));
map.putString("mnc", Integer.toString(mnc));
map.putString("carrierName", carrierName.toString());
map.putString("simSlotIndex", Integer.toString(simSlotIndex));
map.putString("networkCountry", networkCountry);

result.pushMap(map);
}
callback.invoke(result);
} catch (Exception e) {
e.printStackTrace();
callback.invoke(new String(""));
}
}

@Override
public Map<String, Object> getConstants() {

Expand Down Expand Up @@ -75,4 +113,4 @@ public Map<String, Object> getConstants() {

return constants;
}
}
}
23 changes: 23 additions & 0 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.