flutter使用image_picker报错:PlatformException(already_active, Image picker is already active,null)
flutter使用image_picker报错:PlatformException(already_active, Image picker is already active,null)flutter使用image_picker报错:PlatformException(already_active, Image picker is already active,null)由于使用了flutter
flutter使用image_picker报错:PlatformException(already_active, Image picker is already active,null)
flutter使用image_picker报错:PlatformException(already_active, Image picker is already active,null)
由于使用了flutter_boost,需要使用红框中的部分,所以不能继承FlutterActivity,然而这样,在我使用image_picker的时候,点击拍摄进入相机,第一次可以进入,再次点击就进不去了,还会报PlatformException(already_active, Image picker is already active,null)这个错,看了下image_picker的源码,发现在ImagePickerPlugin中
于是找到ActivityPluginBinding,然后找到它的实现类FlutterEngineActivityPluginBinding,发现了addActivityResultListener放法和onActivityResult方法,
ImagePickerDelegate刚好实现了ActivityResultListener,所以就走到了ImagePickerDelegate的onActivityResult方法里面,那么怎么才能在MainActivity走到这里呢?这里会发现我在onCreate方法创建了一个FlutterFragment(flutter_boost)方法,点进去,找到里面的onActivityResult方法
FlutterFragment(flutter-boost)—>FlutterActivityAndFragmentDelegate(flutter-boost)—>ActivityControlSurface(flutter-boost)—>FlutterEnginePluginRegistry(flutter)—>ImagePickerDelegate(image-picker)
经过这样的调用,就会走到ImagePickerDelegate的onActivityResult方法了,所以最后的解决方法是重写MainActivity的onActivityResult,调用FlutterFragment(flutter-boost)的onActivityResult方法
最后,如果你继承的FlutterActivity就不会有这个问题了。
自己的话:
以上是我转载的解决办法在此记录一下,非常感谢。
在百度和Google上找了大半天,终于解决了。作为刚入门的Android开发者,来做Android和flutter的混合开发,着实让我晕头转向。尤其涉及到源码这块,再接再厉吧。
更多推荐
所有评论(0)