Device Nexus 4 Android ver: 4.2.2
Hoping someone else has found this and can explain how to resolve it....
Nexus 4 supports the following preview sizes: -
<
This method calculate the best (for me) screen size for each device. But, I have the same problem like you when I tried this code in the Nexus 4. So, my solution is to have a special case in the end of this method which gets the width of the nexus 4 and calculates the best height for this device.
The last case could be used in all devices. You could delete the first part of the method.
private void setAspectResolutionCamera(Parameters camParams, int screen_width, int screen_height) {
boolean chosen_one_resolution = false;
//Init screen sizes
width_video = ConstantsCamera.VIDEO_ASPECT_WIDTH;
height_video = ConstantsCamera.VIDEO_ASPECT_HEIGHT;
float aspect_ratio = 1f;
int aspect_width = 6000, aspect_height = 6000;
List supported_sizes_list = camParams.getSupportedPreviewSizes();
for (int i = 0; i < supported_sizes_list.size(); i++) {
Size size = supported_sizes_list.get(i);
float aspect = (float) size.height / size.width;
if (ConstantsCamera.VIDEO_ASPECT_RATIO - aspect <= aspect_ratio && (aspect - ConstantsCamera.VIDEO_ASPECT_RATIO >= 0)) {
if (screen_width - size.height <= aspect_width && size.height - screen_width >= 0) {
if (screen_height - size.width < aspect_height) {
height_video = size.width;
width_video = size.height;
aspect_ratio = ConstantsCamera.VIDEO_ASPECT_RATIO - (float) size.height / size.width;
aspect_width = screen_width - size.height;
aspect_height = screen_height - size.width;
chosen_one_resolution = true;
}
}
}
}
//Special case
if (width_video != screen_width && !chosen_one_resolution) {
height_video = screen_width * height_video / width_video;
width_video = screen_width;
}
}