briankabiro / react-native-get-sms-android

React Native module to get messages on an Android device
MIT License
137 stars 68 forks source link

How can I know which sms is delivered? #82

Open gamesover opened 3 years ago

gamesover commented 3 years ago
DeviceEventEmitter.addListener('sms_onDelivery', (msg) => {
  console.log(msg);
});

The above works, just it only returns message "SMS delivered" .

If multiple sms were sent out, how can I know which sms delivery is successful, and which is failed?

Also, I found a strange issue. 1st, I send a sms, callback trigger once, and output 1 SMS delivered 2nd, I send a sms, callback trigger twice, and output 2 SMS delivered ... 10th, I send a sms, callback trigger 10th, and output 10 SMS delivered

gamesover commented 3 years ago

update:

  1. about which is which sms, I resolved it by passing an additional parameter through putExtra and getExtra when broadcasting
  2. about callback is triggered multiple times, since code put registerbroadcast into autoSend method, so each time you call autoSend, you will register broadcast once. Thus, I move broadcasts out to initialize mthod.

Anyone interests, you may refer my fork.

antoniomefa commented 3 years ago

Hi @gamesover ! I'm trying to implement this listener in my project, but it don't show nothing. Can you gime me some help? Where can I put the listener, inside my sendSMS function or in a useEffect? My project sends a bulk of SMS, it works correctly but now I want to know which of them are received and which no. This is my sendSMS function:

const sendSMS = async () => { let increment = 0; const interval = 1000 * parseInt(timeInterval); setIsFinished(false); setIsSending(true); setLoadingText('Enviando...'); setIsLoading(true); var myLoop = setInterval(async function(){ await SmsAndroid.autoSend( globalContext.contacts[increment], message, (fail) => { console.log('Failed with this error: ' + fail); setErrorsCounter(errorsCounter => errorsCounter + 1); }, (success) => { setCounter(counter => counter + 1); //console.log('SMS sent successfully'); }, ); if (increment == globalContext.contacts.length-1) { clearInterval(myLoop); setIsLoading(false); setIsSending(false); setIsFinished(true); } increment++; },interval); }; Thanks!

gamesover commented 3 years ago

Hi @antoniomefa . I have to change the source code of react-native-get-sms-android. When sending sms, I passed sms id. so when android broadcast sms sent/delivery status, it reports the result together with sms id. In this way, I know which sms is sent/delivered.

Detailed you may refer to my fork

trungbmt commented 2 years ago

Hi @gamesover , can you share the code :(