shounakmulay / Telephony

Flutter plugin for telephony features like query device sms directory, listen for incoming messages, retrieve various network parameters, etc.
https://telephony.shounakmulay.dev
MIT License
138 stars 126 forks source link

Can't Access File() with Background handler #154

Open XeroDays opened 2 years ago

XeroDays commented 2 years ago

Error:

mostly : [Unhandled Exception: NoSuchMethodError: sometimes : failed to attach to thread flutter

How to Recreate?

  1. Initialise Background listener.
  2. Add path_provider: ^2.0.9 in pubspec.yaml
  3. use the following as background method.

    static Future<dynamic> myBackgroundMessageHandler(SmsMessage message) async {
    print("onBackgroundMessage: " + message.body!);
    
    await getExternalStorageDirectory()  
    return Future<void>.value();
    }
XeroDays commented 2 years ago
image
XeroDays commented 2 years ago

Update

The error occurs when using this dependency : path_provider: ^2.0.9 I don't know why is is happening but i removed this dependency and replace it with external_path: ^1.0.1

now everything works fine!