expo-android-sms-sender v1.0.1
š© Expo Android SMS Sender
Expo Android SMS Sender is a lightweight, easy-to-use library for sending SMS messages and retrieving SIM card information in React Native applications using the Expo Modules API. This package is designed specifically for Android devices.
ā This library only works on Android. Sending SMS programmatically is not possible on iOS due to Apple's security restrictions. If you need to open the messaging app on iOS instead, consider using expo-sms
.
š Features
- Send SMS messages directly from your React Native app.
- Retrieve available SIM cards on dual-SIM devices.
- Select a specific SIM card for sending messages.
- Built with Expo Modules API for better native integration.
š¦ Installation
This package requires a bare Expo project with a development build because it uses native code. Follow these steps to install:
1ļøā£ Install the package:
npm install expo-android-sms-sender
2ļøā£ Rebuild your project
Since this package includes native code, you must rebuild your app using a development build:
eas build --profile development --platform android
or if using Expo Dev Client:
npx expo run:android
š Permissions
- The
SEND_SMS
permission is required for thesendSms()
function. - The
READ_PHONE_STATE
permission is required for thegetSimCards()
function.
Make sure to request these permissions at runtime before using the respective functions.
š API Reference
getSimCards(): Promise<SimCard[]>
Retrieves information about available SIM cards on the device.
Returns:
An array of objects with the following properties:
type SimCard = {
id: number; // Unique SIM card identifier (subscription ID)
displayName: string; // SIM name as displayed in system settings
carrierName: string; // Mobile network carrier name
slotIndex?: number; // Slot index (if available)
};
Example usage:
import { getSimCards } from "expo-android-sms-sender";
import { PermissionsAndroid } from 'react-native';
async function fetchSimCards() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
const sims = await getSimCards();
console.log("Available SIM Cards:", sims);
} else {
console.log("READ_PHONE_STATE permission denied");
}
} catch (error) {
console.error("Error fetching SIM cards:", error);
}
}
sendSms(phoneNumber: string, text: string, simCardId?: number): Promise<void>
Parameters:
phoneNumber
(string) ā The recipient's phone number.text
(string) ā The message body.simCardId
(number, optional) ā The ID of the SIM card to use. If omitted, the system will use the default SIM.
Example usage:
import { sendSms } from "expo-android-sms-sender";
import { PermissionsAndroid } from 'react-native';
async function sendMessage() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.SEND_SMS
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
await sendSms("PHONE_NUMBER_TO_SEND_TO", "Hello from Expo!");
console.log("Message sent successfully!");
} else {
console.log("SEND_SMS permission denied");
}
} catch (error) {
console.error("Error sending SMS:", error);
}
}
š¢ Reporting Issues & Feature Requests
If you encounter a bug, have a question, or want to request a feature, please open an issue on GitHub.
When submitting an issue, please include:
- A clear description of the problem.
- Steps to reproduce it.
- Any relevant logs or error messages.
- The version of the library and your Expo SDK version.
We appreciate your feedback and contributions!
š¤ Contributing
We welcome contributions from the community! If you'd like to contribute:
- Fork the repository on GitHub.
- Create a new branch (feature/my-feature or fix/bug-name).
- Commit your changes with clear messages.
- Submit a pull request and wait for review.
Make sure to follow the project's coding guidelines.
š License
MIT license. Feel free to use and modify.