arsamme / flutter-sms-retriever

Flutter plugin for retrieving OTP code sent in sms automatically and without getting SMS permission in Android.
MIT License
9 stars 17 forks source link

com.package.MainActivity cannot be cast to io.flutter.embedding.android.FlutterActivity #3

Closed thomaslee-u closed 2 years ago

thomaslee-u commented 3 years ago

I am using along with the local_auth which need to set up integration on Android using FlutterFragmentActivity

https://github.com/flutter/plugins/tree/master/packages/local_auth#android-integration

But it has some incompatible issue with SmsRetrieverPlugin.kt

i saw someone mention to replace FlutterActivity with Activity but i am not sure https://github.com/AmolGangadhare/flutter_barcode_scanner/issues/128

E/AndroidRuntime(31632): FATAL EXCEPTION: main
E/AndroidRuntime(31632): Process: com.example.example, PID: 31632
E/AndroidRuntime(31632): java.lang.ClassCastException: com.example.example.MainActivity cannot be cast to io.flutter.embedding.android.FlutterActivity
E/AndroidRuntime(31632):    at me.arsam.sms_retriever.SmsRetrieverPlugin.onAttachedToActivity(SmsRetrieverPlugin.kt:59)
E/AndroidRuntime(31632):    at io.flutter.embedding.engine.FlutterEnginePluginRegistry.add(FlutterEnginePluginRegistry.java:143)
E/AndroidRuntime(31632):    at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:18)
E/AndroidRuntime(31632):    at com.example.example.MainActivity.configureFlutterEngine(MainActivity.kt:11)
E/AndroidRuntime(31632):    at io.flutter.embedding.android.FlutterFragment.configureFlutterEngine(FlutterFragment.java:950)
E/AndroidRuntime(31632):    at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:181)
happysingh23828 commented 2 years ago

did you find any solution ? @arsamme

happysingh23828 commented 2 years ago

I have forked and fix this repository. You can use add dependency like this into your pubspec.yaml

android_sms_retriever:
    git:
      url: https://github.com/happysingh23828/flutter-sms-retriever
arsamme commented 2 years ago

@happysingh23828 I've merged and published your PR. Thanks.

arsamme commented 2 years ago

@happysingh23828 One time consent not working after changing FlutterActivity to FlutterFragmentActivity because onActivityResult does not get called. Do you have any idea?

happysingh23828 commented 2 years ago

@arsamme I'll check on this, Ideally it should not have any impact by changing from FlutterActivity to FlutterFragmentActivity