how can i send sms programmatically in react-native? [closed]

会有一股神秘感。 提交于 2019-12-21 16:56:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!