Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to stop listening after collecting my sms #194

Open
fumant2000 opened this issue Oct 12, 2023 · 0 comments
Open

how to stop listening after collecting my sms #194

fumant2000 opened this issue Oct 12, 2023 · 0 comments

Comments

@fumant2000
Copy link

how do i stop listening after i've received the sms i'm interested in, or how do i make it so that if after 30 seconds we've received nothing we can stop listening and return a waiting message. here's the function I've made.

`import 'package:telephony/telephony.dart';

import 'dart:async';

Future smsSensor() async {
Completer completer = Completer();
Telephony telephony = Telephony.instance;

try {
// Créez une fonction pour vérifier si un message vous intéresse
bool isInterestingMessage(SmsMessage message) {
if (message.address == "OrangeMoney" ||
message.address == "MobileMoney") {
int currentTime = DateTime.now().millisecondsSinceEpoch;
int timeDifference = currentTime - message.date!;
int minutes = timeDifference ~/ 60000;

    // Vérifiez si le message a été reçu il y a moins d'une minute
    if (minutes < 2) {
      // Ajoutez ici votre logique pour filtrer les messages en fonction de leur contenu
      // Par exemple, vérifiez s'il contient des mots-clés spécifiques
      if (message.body?.contains("Transfert de") == true ||
          message.body?.contains("Vous avez recu") == true ||
          message.body
                  ?.contains("avez effectue avec succes le retrait de") ==
              true ||
          message.body?.contains("You have received") == true ||
          message.body?.contains(
                  "Vous avez effectue avec succes le retrait de") ==
              true ||
          message.body?.contains("Retrait d'argent reussi par") == true) {
        return true;
      }
    }
  }
  return false;
}
telephony.listenIncomingSms(
  onNewMessage: (SmsMessage message) {
    if (isInterestingMessage(message)) {
      completer.complete(message.body!);
    }
  },
  listenInBackground: false,
);

} catch (e) {
print("wow wow wow wow wow .... va regarder:" + e.toString());
}

String sms = await completer.future;
return sms;
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant