react-native-get-sms-android icon indicating copy to clipboard operation
react-native-get-sms-android copied to clipboard

How can I know which sms is delivered?

Open gamesover opened this issue 3 years ago • 4 comments

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 avatar Mar 12 '21 17:03 gamesover

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.

gamesover avatar Mar 14 '21 16:03 gamesover

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!

antoniomefa avatar Apr 28 '21 01:04 antoniomefa

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

gamesover avatar Apr 29 '21 15:04 gamesover

Hi @gamesover , can you share the code :(

trungbmt avatar Jan 18 '22 15:01 trungbmt