Camera api preview not showing - android

I'm trying to implement my own camera without using the camera intent.
When I try to setPreviewSize() from the camera.getParameters().getSupportedPreviewSizes() highest resolution it doesn't display the preview on some devices. It work for the majority but not all...
This is my res supported list
SIZE 1280 960
SIZE 1280 720
SIZE 800 480
SIZE 720 720
SIZE 720 480
SIZE 640 480
SIZE 352 288
SIZE 320 240
SIZE 176 144
Not working for 1280 * 960 but ok for 1280 * 720 for this specific device. Is it kind of magical or something :-/
Tcs for help !

First of all, note the official recommendation on https://developer.android.com/reference/android/hardware/Camera.Parameters.html:
This class was deprecated in API level 21.
We recommend using the new android.hardware.camera2 API for new applications.
Now, could you please be more specific on which devices doesn't it work? It seems like it is not your fault since some devices simply just won't support every resolution.

Related

Conversion from px to dp for Google nexus 7

I am new to tablet application development. I am having Google Nexus7 with screen resolution (600 * 960 dip) So I want to know is it fall in to mdip category?
According to that 1px = 1dp (baseline). But If I follow this its not looks good on tablet. I am creating separate layout folder for nexus7 -sw600dp and mention sizes according to mdip but it not working. My images also not looking good. What I want to know what is actual conversion rate for google nexus 7. Need help.
Formula: pixels = dips * (density / 160)
The Nexus 7 is 800x1280 with a 213 px density, which means it's resolution code is tvdpi (which means you can have a folder called drawable-tvdpi).
You can measure available screen size, minus window decorations, with:
this.getResources().getConfiguration().screenWidthDp;
this.getResources().getConfiguration().screenHeightDp;
On my N7, it returns 600 dp w, 888 dp h. Following the above formula, 888 dp height is 1280px - window decoration.
The Nexus7 is a unique device, with a somewhat strange dpi structure.
For nexus 7
layout-large-hdpi
Here is a very good explanation (from Dianne Hackborn - an Android engineer at Google): Dianne Hackborn explains the unique resolution of the Nexus7
Note: The app takes images from these folders only if you have not given higher precedence qualifiers. For example if you have given a layout folder like layout-sw360dp the app will take only the images from this folder even if you have given separate layouts like the one I said above. Because in android there is an order of precedence in which you have to give layouts.
Screen Density
Commonly referred to as dpi (dots per inch). Android groups all actual screen densities into four generalized densities: low (120), medium (160), high (240), and extra high (320). A device such as Galaxy Nexus has "extra high" screen density (more specifically, the dpi value is set at 320). The Nexus 7 uses "tvdpi" - i.e. 213 dpi.
Density Independent Pixel
Commonly referred to as dp. This is the virtual pixel unit used when displaying content. The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen. To calculate dp use the following formula:
px = dp * (dpi / 160)
or equivalently:
dp = (px / dpi) * 160
The reason Nexus 7 can show more content than the Galaxy Nexus despite having similar resolutions is this: the dpi of Nexus 7 is lower than Galaxy Nexus.
Galaxy Nexus (320 dpi, 720 pixels wide)
(720 / 320) * 160 = 360 dp
Nexus 7 (213 dpi, 800 pixels wide)
(800 / 213) * 160 = 600 dp
This means that when apps are rendering on the Galaxy Nexus, the width of the screen is actually 360 dp (rendered using 720 pixels). Whereas on the Nexus 7, the width of the screen is 600 dp (rendered using 800 pixels).
Try below code, give pixel value to below method it will give you result in dp.
public int convertSizeToDeviceDependent(int value) {
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
return ((dm.densityDpi * value) / 160);
}

How to create different layout for Galaxy S4 and Nexus 4

I am using "layout-sw360dp" for both Galaxy S4 and Nexus 4 devices but in my screen displaying some space on Galaxy S4. so can i make different layout for both Galaxy S4 and Nexus 4. if it is possible then please give me the solution.
For Galaxy s4 use layout-xxhdpi
For Nexus 4 use layout-xhdpi
Galaxy S4 -- 1080 x 1920 pixels -- 5.0" -- 441 ppi -- xxhdpi
Nexus 4 -- 1280 x 768 pixels -- 4.7" -- 320 ppi -- xhdpi
You have to make different images to fit to the resolution of these devices
As per other answers one device is 640 x 360 dp and the other 640 x 384 dp.
You don't want to make a different layout for them, because you will sooner or later see a device 640 x 372 dp or 640 x 388 dp.
Instead make your layout elastic and don't hardcode pixels (density independent pixels can also be badly hardcoded).
ok here goes...
for reference
this is older layout folder naming conventions but you get the point.
You must convert everything to mdpi to go into the following buckets.
buckets for layouts are :
xlarge 960 x720 min
large 640 x480 min
normal 470 x 320 min
small 426x 320 min
scaling ratio
3:4:6:8:12
this means that you must multiple ldpi * 3/4 to go from ldpi to mdpi
and you must multiple mdpi * 4/6 to go from mdpi to hdpi
and you must multiple hdpi * 6/8 to go from hdpi to xhdpi
and you must multiple xhdpi * 8/12 to go from xhdpi to xxhdpi
so to answer the question....
s4 is xxhdpi which means the scaling ratio is 4/12 or 1/3. This means that you have to convert from xxhdpi to mdpi to place in a layout folder properly.
so 1080 * 1/3 = 360
and 1920 * 1/3 = 640
so this would place it in a normal layout folder
nexus 4 is xhdpi which means the scaling ratio is 4/8 or 1/2. 4 This means that you have to convert from xhdpi to mdpi to place in a layout folder properly.
so 1280 * 1/2 = 640
and 768 * 1/2 = 384
so this would place it in a normal layout folder as well.
ok, so this doesn't quite cut it because they are different resolutions. we can make up folders with the new naming conventions. for example the smallest width for the s4 is 360 while the smallest width for the nexus 4 is 384. so folders could be sw360dp and sw384dp.
you could also name the folder layout-xxhdpi which would catch the s4 but not the nexus 4
be aware: Just to throw another one out there what if you had an s3 as well. that would go in the sw360dp folder as well. so I guess you would have to differ between them as well. if you used layout-xxhdpi above then you could use sw360dp here and sw384dp above as well. cover them all.
thanks
Both these phones have different screen size and resolution , that leads to different density as well .
As per my knowledge -
Galaxy s4 has 1080 x 1920 pixels, 5.0 inches (~441 ppi pixel density).
And
Nexus 4 has 1280 x 768 pixels, 4.7 inches (320 ppi ).
You will have to design the layouts (and images as well ) according to the phones specifications.
for nexus 4 use below layout.
layout-sw360dp
both galaxy s3 and nexus 4 have same layouts.

Screenshot sizes for publishing android app on Google Play

On the developer's console when you go to publish your android application the screenshots are needed with the following specifications,
320 x 480, 480 x 800, 480 x 854,1280 x 720, 1280 x 800 24 bit PNG or JPEG (no alpha) Full bleed, no border in art.
Now on this link it says, "You may upload up to 8 screenshots."
My questions is,
What are the sizes for the last five screenshots? - The first three being - 320 x 480, 480 x 800, 480 x 854
Is it 480 x 800 OR 480 x 854 for the second to eight screenshot or is it that second should be 480 x 800 and third should be 480 x 854 and fourth - eighth?
Are the sizes 1280 x 720, 1280 x 800 only for tablets and are they optional?
When I publish apps I use the following screenshot sizes:
Phone: 1080 x 1920 I prepare 8 images with title, some fancy background and a screenshot inside a smartphone mockup. So it's more than a simple screenshot. It gives some nice branding and helps you to stand out from other apps out there.
Tablet 7": 1200 x 1920 - I do actually a couple of raw screenshots of 7" emulator so that the user could know how the layout will appear on his device. No fancy design with titles etc.
Tablet 10": 1800 x 2560 - same thing here, just a couple of raw screenshots.
all in .png format.
Hope this helps.
We require 2 screenshots.
Use: Displayed on the details page for your application in Google
Play.
You may upload up to 8 screenshots each for phone, 7” tablet and
10” tablet.
Specs: Minimum dimension: 320 pixels. Maximum dimension: 3840 pixels.
The maximum dimension of your screenshot cannot be more than twice as
long as the minimum dimension. You may use 24 bit PNG or JPEG image
(no alpha). Full bleed, no border in art.
We recommend adding screenshots of your app running on a 7" and 10"
tablet. Go to ‘Store listing’ page in your Developer Console to add
tablet apps screenshots.
https://support.google.com/googleplay/android-developer/answer/1078870?hl=en&ref_topic=2897459
At last! I got the answer to this, the size to edit it in photoshop is: 379x674
You are welcome
It has to be any one of the given sizes and a minimum of 2 but up to 8 screenshots are accepted in Google Playstore.
You can upload up to 8 screenshots. Those screenshots must be one of the dimensions (sizes) you listed; you can have multiple screenshots of the same dimensions.
The files need to be in a JPEG or PNG format of 24 bits, in a 2:1 ratio if it is a portrait and a 16:9 ratio for landscapes. Be careful that if you go for different sizes: the maximum size should not be more than twice bigger than the minimum size.

How to convert resolution to dpi

I did my analysis and found that most of the users of my application will be of samsung galaxy S2, and samsung galaxy note . Doing research on their technical spec, I found:
Galaxy S2:
480 x 800 pixels, 4.3' display
Galaxy Note:
1280 x 800, 5.3”screen
How can I categorize these into Layout size and desnity level? I think I can figure out the layout size as mentioned in the android development page
However I am unable to know the density level (low, medium high xhigh). They say that I need the dpi but in functional spec, I rarely see the dpi, I just see the above resolution
Thank you
Calculate the density first Density=Square root((wp*wp)+(hp*hp))/di
where wp is width resolution in pixels, hp is height resolution in pixels and di is diagonal size in inches. It would come ~208 for S2.
ldpi ~120dpi,mdpi ~160dpi, hdpi~240dpi, xhdpi ~320dpi. Compare from these values of dpi
Not sure if I understand you correctly but you can request the density level and the dpi from the DisplayMetrics class. Using resolution and density you can approximate the display's size.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

Supported camera preview sizes for popular Android handsets

I'm working with camera preview frames, and need to make a decision about what minimum preview size I will work with. I need fairly high resolution, and am trying to figure out the highest preview resolution I can get across the more popular Android handsets and OS versions. (Judging by this question about Nexus One / Froyo preview sizes, it looks like they sometimes change across OS versions for the same device.)
Is there a resource anywhere that basically lists the output of android.hardware.Camera.Parameters.getSupportedPreviewSizes() for lots of different devices (or device/OS version pairs)?
Alternatively, if there is no such listing, this question could become such a resource. I will very happily upvote any answers that include new individual data points for specific handsets / OS versions.
And to forestall the obvious comment: Yes, I know I will need to test my code on lots of devices anyway. But ideally I would like to make some reasonably informed decisions about resolution early on, without having to purchase a bevy of devices just to get started.
My experience tells me, that 640x480 is available almost everywhere, and even if bigger resolutions are advertised by camera object, not all of them are actually usable.
I experienced segfaults on HTC Hero when I tried maximal resolution - data buffer used
for passing preview images is mmaped, and this size seems to be limited
HTC Wildfire running Froyo
1280 x 720 1.778
800 x 480 1.667
768 x 432 1.778
720 x 480 1.500
640 x 480 1.333
576 x 432 1.333
480 x 320 1.500
400 x 240 1.667
384 x 288 1.333
352 x 288 1.222
320 x 240 1.333
272 x 272 1.000
240 x 240 1.000
240 x 160 1.500
176 x 144 1.222
Lots of data here: http://www.kirill.org/ar/ar.php
My Nexus 9 running Lollipop has these front camera sizes:
1472 x 1104 1.333
736 x 552 1.333
1280 x 720 1.778
720 x 480 1.500
640 x 480 1.333
352 x 288 1.222
320 x 240 1.333
176 x 144 1.222
Nexus 4 running Icecream Sandwich
1280 x 720 1.778
800 x 480 1.667
768 x 432 1.778
720 x 480 1.500
640 x 480 1.333
576 x 432 1.333
480 x 320 1.500
384 x 288 1.333
352 x 288 1.222
320 x 240 1.333
240 x 160 1.500
176 x 144 1.222

Categories

Resources