Flutter Plugin not reaching onActivityResult within plugin and reaches with result to MainActivity

1,877 views
Skip to first unread message

Muthaiah Thiagarajan

unread,
Sep 24, 2019, 8:20:40 AM9/24/19
to Flutter Development (flutter-dev)
Need some help on plugin development with flutter on Android. Facing the following issue.


class MyPlugin : MethodCallHandler, PluginRegistry.ActivityResultListener{
    override fun onActivityResult(requestCode: Int, p1: Int, data: Intent?): Boolean {
   Doesnt reach here - Actually it should reach here as i have registered on the constructor of this plugin
    }

constructor(registrar: Registrar) {
this.registrar = registrar
registrar.addActivityResultListener(this)

}

companion object {
@JvmStatic
fun registerWith(registrar: Registrar) {
val channel = MethodChannel(registrar.messenger(), "my_plugin")
val plugin = MyPlugin(registrar)
channel.setMethodCallHandler(plugin)
}
}

}



class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)

}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
   Reaches here
}
}


Muthaiah Thiagarajan

unread,
Sep 24, 2019, 8:22:00 AM9/24/19
to Flutter Development (flutter-dev)
I added the override on the MainActivity to find the problem, not intended to have that override method.

Alan Maulana

unread,
Oct 2, 2019, 5:30:58 AM10/2/19
to Flutter Development (flutter-dev)
You can adds a callback allowing the plugin to take part in handling incoming calls to Activity.onActivityResult(int, int, Intent) by using this method Registrar#addActivityResultListener. I have implemented it in my flutter package here https://github.com/alann-maulana/flutter_beacon/blob/master/android/src/main/java/com/flutterbeacon/FlutterBeaconPlugin.java#L71
Reply all
Reply to author
Forward
0 new messages