cordova-plugin-siminfo
v1.0.0
Published
Cordova plugin to fetch SIM card and device information on Android and iOS
Maintainers
Readme
cordova-plugin-siminfo
A Cordova plugin to retrieve SIM card and device information on Android and iOS platforms.
Features
- ✅ Get SIM card information (carrier, country code, subscription ID)
- ✅ Support for dual SIM devices
- ✅ Device ID retrieval
- ✅ eSIM availability detection (Android)
- ✅ SIM slot status checking
- ✅ Cross-platform support (Android & iOS)
Installation
Install from npm
cordova plugin add cordova-plugin-siminfoInstall from GitHub
cordova plugin add https://github.com/nikhilbhanda/cordova-plugin-siminfo.gitInstall locally
cordova plugin add /path/to/cordova-plugin-siminfoSupported Platforms
- Android (API 21+)
- iOS (12.0+)
Usage
Basic Example
// Call the plugin method
SimInfo.getSimInfo(
function(result) {
console.log('SIM Info:', result);
// Handle success
},
function(error) {
console.error('Error:', error);
// Handle error
}
);Response Format
Android Response
{
"deviceId": "android_device_id",
"eSimAvailable": true,
"isSimInserted": true,
"isBothSimInserted": false,
"simSlotsWithSim": [0],
"sims": [
{
"slot": 0,
"carrier_id": "Carrier Name",
"country_code": "us",
"subscription_id": 12345
},
{
"slot": 1,
"info": "No SIM Installed"
}
],
"UniqueData": "deviceId=android_device_id_country_code=us_subscription_id=12345_carrier_id=Carrier Name"
}iOS Response
{
"default": {
"carrierName": "Carrier Name",
"mobileCountryCode": "310",
"mobileNetworkCode": "260",
"isoCountryCode": "us",
"allowsVOIP": true
}
}Complete Integration Example
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
// Check if plugin is available
if (window.SimInfo) {
getSimInformation();
} else {
console.error('SimInfo plugin not available');
}
}
function getSimInformation() {
SimInfo.getSimInfo(
function(result) {
console.log('Success! SIM Info received:');
// Platform-specific handling
if (device.platform === 'Android') {
console.log('Device ID:', result.deviceId);
console.log('eSIM Available:', result.eSimAvailable);
console.log('SIM Inserted:', result.isSimInserted);
console.log('Both SIMs Inserted:', result.isBothSimInserted);
result.sims.forEach(function(sim, index) {
console.log('SIM Slot ' + sim.slot + ':', sim);
});
} else if (device.platform === 'iOS') {
console.log('iOS Carrier Info:', result);
}
},
function(error) {
console.error('Failed to get SIM info:', error);
}
);
}Permissions
Android
The plugin automatically adds the required permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />Important: Starting from Android 6.0 (API level 23), you need to request this permission at runtime. You may want to use a permissions plugin like cordova-plugin-android-permissions to handle runtime permissions.
Runtime Permission Example
// Check if we have permission
var permissions = cordova.plugins.permissions;
permissions.checkPermission(
permissions.READ_PHONE_STATE,
function(status) {
if (!status.hasPermission) {
// Request permission
permissions.requestPermission(
permissions.READ_PHONE_STATE,
function(status) {
if (status.hasPermission) {
// Permission granted, get SIM info
SimInfo.getSimInfo(successCallback, errorCallback);
}
},
errorCallback
);
} else {
// Already have permission
SimInfo.getSimInfo(successCallback, errorCallback);
}
},
null
);iOS
The plugin uses the CoreTelephony framework. No special permissions are required in most cases, but carrier information availability depends on iOS restrictions and carrier configurations.
API Reference
Methods
getSimInfo(successCallback, errorCallback)
Retrieves SIM and device information.
Parameters:
successCallback(Function): Called with the SIM information objecterrorCallback(Function): Called with an error message string
Returns: void
Android Response Fields
| Field | Type | Description |
|-------|------|-------------|
| deviceId | String | Android device ID (ANDROID_ID) |
| eSimAvailable | Boolean | Whether the device supports eSIM |
| isSimInserted | Boolean | Whether at least one SIM is inserted |
| isBothSimInserted | Boolean | Whether both SIM slots have SIMs (dual SIM devices) |
| simSlotsWithSim | Array | Array of slot indices that have SIMs inserted |
| sims | Array | Array of SIM information objects |
| UniqueData | String | Concatenated unique identifier string |
iOS Response Fields
| Field | Type | Description |
|-------|------|-------------|
| carrierName | String | Name of the carrier |
| mobileCountryCode | String | Mobile Country Code (MCC) |
| mobileNetworkCode | String | Mobile Network Code (MNC) |
| isoCountryCode | String | ISO country code |
| allowsVOIP | Boolean | Whether the carrier allows VoIP |
Troubleshooting
Android
Issue: "Permission denied" error
- Solution: Make sure you've requested the
READ_PHONE_STATEpermission at runtime on Android 6.0+
Issue: Getting "No SIM Installed" for all slots
- Solution: Check if SIM cards are properly inserted and the device has cellular capability
Issue: Empty carrier information
- Solution: Some carriers or devices may not provide complete information. This is a limitation of the Android API.
iOS
Issue: Empty carrier information
- Solution: iOS restricts carrier information access. Some information may not be available depending on iOS version and carrier configuration.
Issue: Getting null values
- Solution: Make sure the device has an active cellular connection and valid SIM card.
Platform Differences
| Feature | Android | iOS | |---------|---------|-----| | Device ID | ✅ ANDROID_ID | ❌ Not available | | Dual SIM support | ✅ Full support | ⚠️ Limited (iOS 12+) | | eSIM detection | ✅ Available | ❌ Not provided | | Subscription ID | ✅ Available | ❌ Not available | | SIM slot info | ✅ Available | ⚠️ Limited |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Issues
If you encounter any issues, please report them on the GitHub Issues page.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Nikhil Bhanda [email protected]
Changelog
1.0.0
- Initial release
- Android support with dual SIM
- iOS support with CoreTelephony
- eSIM detection (Android)
- Device ID retrieval (Android)
