fluttercommunity / flutter_sms

A Flutter plugin to Send SMS and MMS on iOS and Android. If iMessage is enabled it will send as iMessage on iOS. This plugin must be tested on a real device on iOS. Maintainer: @rodydavis
https://fluttercommunity.github.io/flutter_sms/
MIT License
241 stars 176 forks source link

Platform NullPointerException when calling sendSMS() headless #45

Open jasonkaruza opened 3 years ago

jasonkaruza commented 3 years ago

Hello,

Flutter Doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.5, on Microsoft Windows [Version 10.0.19041.928], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.56.0)
[√] Connected device (4 available)

Error stack trace:

 *** ERR: (null ctxt) Exception occurred when sending SMS message: PlatformException(error, null, null, kotlin.KotlinNullPointerException
I/flutter (20578):      at com.example.flutter_sms.FlutterSmsPlugin.canSendSMS(FlutterSmsPlugin.kt:58)
I/flutter (20578):      at com.example.flutter_sms.FlutterSmsPlugin.onMethodCall(FlutterSmsPlugin.kt:39)
I/flutter (20578):      at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
I/flutter (20578):      at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
I/flutter (20578):      at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
I/flutter (20578):      at android.os.MessageQueue.nativePollOnce(Native Method)
I/flutter (20578):      at android.os.MessageQueue.next(MessageQueue.java:335)
I/flutter (20578):      at android.os.Looper.loop(Looper.java:206)
I/flutter (20578):      at android.app.ActivityThread.main(ActivityThread.java:8512)
I/flutter (20578):      at java.lang.reflect.Method.invoke(Native Method)
I/flutter (20578):      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
I/flutter (20578):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
I/flutter (20578): )
I/flutter (20578): Stack trace

Scenario: My app runs a headless process that I'd like to send an SMS message from. Any guidance for out to get your plugin (or any plugin to do this in a headless fashion) is greatly appreciated.