sodipto / flutter-phone-state-background

MIT License
5 stars 7 forks source link

Error: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long #10

Open sapoi opened 1 year ago

sapoi commented 1 year ago

Hello,

I have a problem with your package. When I run it on a real device, this error occurs:

PlatformException (PlatformException(error, java.lang.Integer cannot be cast to java.lang.Long, null, java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
    at me.sodipto.phone_state_background.PhoneStateBackgroundPlugin.onMethodCall(PhoneStateBackgroundPlugin.kt:56)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7266)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
))

These are my values when the application crashes:

Screenshot 2023-07-07 at 17 52 44

The method onEventCallback!.toRawHandle() in lib/phone_state_background.dart on line 32 returns int, but line 56 in android/src/main/kotlin/me/sodipto/phone_state_background/PhoneStateBackgroundPlugin.kt expects long.

Can you please fix the conversion so it works with int values as well?

sapoi commented 1 year ago

Fix proposed in pull request #11.