jaumard / sms_autofill

Flutter plugin to provide SMS code autofill support
MIT License
281 stars 173 forks source link

version 2.1.0 #136

Closed briouyaasmae closed 2 years ago

briouyaasmae commented 2 years ago

After using version 2.1.0 I get this issue E/AndroidRuntime(30428): java.lang.IllegalArgumentException: Receiver not registered: com.jaumard.smsautofill.SmsAutoFillPlugin$SmsBroadcastReceiver@ca372f0 and app crash

jaumard commented 2 years ago

Hey, thanks for the report, do you have steps to reproduce this please ?

briouyaasmae commented 2 years ago
Screen Shot 2021-09-15 at 13 36 30

I'm using those functions and I'm calling them in initstate 

When I login for the first time and listen to otp, everything works well, but if I logout and login for the second time, the app crashes and this error is shown.

jaumard commented 2 years ago

Maybe that's because you listen to the code but actually never unregister it? Does it work better by adding:


  @override
  void dispose() {
    SmsAutoFill().unregisterListener();
    super.dispose();
  }

I'll make more test on my side see if I can reproduce it too

briouyaasmae commented 2 years ago
Screen Shot 2021-09-15 at 14 27 19

When I'm using SmsAutoFill().unregisterListener()

jaumard commented 2 years ago

ok very weird, so far I can't reproduce. Even don't see how the receiver can't be registered...

Basically I create it like this:

unregisterReceiver();// unregister existing receiver
broadcastReceiver = new SmsBroadcastReceiver(new WeakReference<>(SmsAutoFillPlugin.this));
activity.registerReceiver(broadcastReceiver, new IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION));

So when it's created; it's registered. Then to unregister I do it only when it is not created.

private void unregisterReceiver() {
        if (broadcastReceiver != null) {
            activity.unregisterReceiver(broadcastReceiver);
            broadcastReceiver = null;
        }
    }

It blow my mind :D I'll keep searching that! Thanks for the details

jaumard commented 2 years ago

So I have added a try/catch for now to avoid crash. As I can't reproduce of find what could go wrong... So should be good on 2.1.1. Let me know if there is any other issue.

danghoanguet commented 1 year ago

So I have added a try/catch for now to avoid crash. As I can't reproduce of find what could go wrong... So should be good on 2.1.1. Let me know if there is any other issue.

So this issue is still there try catch just to prevent app crashes. I am facing an issue that after 5 minutes which is timeout i have to relisten by calling listenForCode again but sometimes after relisten in onReceive status.getStatusCode() still 15(timeout)