diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index e3155d733468..c7936cab268e 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.5+2 + +* Ensure communication from JAVA to Dart is done on the main UI thread. + ## 0.6.5+1 * Fixes picture captures causing a crash on some Huawei devices. diff --git a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java index 2fee13816b51..0c3487defc9f 100644 --- a/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java +++ b/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/DartMessenger.java @@ -1,5 +1,7 @@ package io.flutter.plugins.camera; +import android.os.Handler; +import android.os.Looper; import android.text.TextUtils; import androidx.annotation.Nullable; import io.flutter.plugin.common.BinaryMessenger; @@ -56,7 +58,25 @@ void sendCameraErrorEvent(@Nullable String description) { }); } - void send(EventType eventType) { + void send(CameraEventType eventType) { + send(eventType, new HashMap<>()); + } + + void send(CameraEventType eventType, Map args) { + if (cameraChannel == null) { + return; + } + new Handler(Looper.getMainLooper()) + .post( + new Runnable() { + @Override + public void run() { + cameraChannel.invokeMethod(eventType.method, args); + } + }); + } + + void send(DeviceEventType eventType) { send(eventType, new HashMap<>()); } @@ -64,6 +84,13 @@ void send(EventType eventType, Map args) { if (channel == null) { return; } - channel.invokeMethod(eventType.toString().toLowerCase(), args); + new Handler(Looper.getMainLooper()) + .post( + new Runnable() { + @Override + public void run() { + deviceChannel.invokeMethod(eventType.method, args); + } + }); } } diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index 19049b5e247f..5f9a3acb770a 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -2,7 +2,7 @@ name: camera description: A Flutter plugin for getting information about and controlling the camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video, and streaming image buffers to dart. -version: 0.6.5+1 +version: 0.6.5+2 homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera dependencies: