Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.5.1

* Can now be compiled with earlier Android sdks below 21 when
`<uses-sdk tools:overrideLibrary="io.flutter.plugins.camera"/>` has been added to the project
`AndroidManifest.xml`. For sdks below 21, the plugin won't be registered and calls to it will throw
a `MissingPluginException.`

## 0.5.0

* **Breaking Change** This plugin no longer handles closing and opening the camera on Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ public void onOrientationChanged(int i) {
}

public static void registerWith(Registrar registrar) {
if (registrar.activity() == null) {
if (registrar.activity() == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// When a background flutter view tries to register the plugin, the registrar has no activity.
// We stop the registration process as this plugin is foreground only.
// We stop the registration process as this plugin is foreground only. Also, if the sdk is
// less than 21 (min sdk for Camera2) we don't register the plugin.
return;
}

final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/camera");

Expand Down Expand Up @@ -126,8 +128,8 @@ public void onMethodCall(MethodCall call, final Result result) {
cameras.add(details);
}
result.success(cameras);
} catch (CameraAccessException e) {
result.error("cameraAccess", e.getMessage(), null);
} catch (Exception e) {
handleException(e, result);
}
break;
case "initialize":
Expand Down Expand Up @@ -168,8 +170,8 @@ public void onMethodCall(MethodCall call, final Result result) {
try {
camera.startPreviewWithImageStream();
result.success(null);
} catch (CameraAccessException e) {
result.error("CameraAccess", e.getMessage(), null);
} catch (Exception e) {
handleException(e, result);
}
break;
}
Expand All @@ -178,8 +180,8 @@ public void onMethodCall(MethodCall call, final Result result) {
try {
camera.startPreview();
result.success(null);
} catch (CameraAccessException e) {
result.error("CameraAccess", e.getMessage(), null);
} catch (Exception e) {
handleException(e, result);
}
break;
}
Expand All @@ -198,6 +200,18 @@ public void onMethodCall(MethodCall call, final Result result) {
}
}

// We move catching CameraAccessException out of onMethodCall because it causes a crash
// on plugin registration for sdks incompatible with Camera2 (< 21). We want this plugin to
// to be able to compile with <21 sdks for apps that want the camera and support earlier version.
@SuppressWarnings("ConstantConditions")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being suppressed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The casting of Exception to RuntimeException. From my understanding of Java, CameraAccessException is the only checked exception that will come from these methods. Otherwise it should be a RuntimeException.

private void handleException(Exception exception, Result result) {
if (exception instanceof CameraAccessException) {
result.error("CameraAccess", exception.getMessage(), null);
}

throw (RuntimeException) exception;
}

private static class CompareSizesByArea implements Comparator<Size> {
@Override
public int compare(Size lhs, Size rhs) {
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.0
version: 0.5.1
authors:
- Flutter Team <flutter-dev@googlegroups.com>
- Luigi Agosti <luigi@tengio.com>
Expand Down