问题
I'm new in react native. I want to add a component for sending SMS in my android application and i have tried several different components but every time i got some errors. Is anyone here done this successfully? please help me.
This is the last error I've got.
回答1:
I recommend this for sending SMS: https://github.com/anarchicknight/react-native-communications
As for the naming collision error, try doing rm -rf node_modules && npm i and then restarting the packager with a clear cache: npm start -- --reset-cache
If that doesn't work, make sure the version of react-native the SMS package matches the version in your package.
回答2:
try this code
String strSmsBody = "Hello";
//sms recipient id
String strReceipents = "abc@gmail.com";
SmsManager sms = SmsManager.getDefault();
List<String> messages = sms.divideMessage(strSmsBody);
for (String message : messages) {
sms.sendTextMessage(strReceipents, null, message, PendingIntent.getBroadcast(
this, 0, new Intent(ACTION_SMS_SENT), 0), null);
}
dont forget to add this line in manifest file
<uses-permission android:name="android.permission.SEND_SMS" />
来源:https://stackoverflow.com/questions/40548664/how-can-i-send-sms-programmatically-in-react-native