If it is determined by the resolution of the Android device's screen, is there a way to programatically get the value of that resolution?

3

There are 3 best solutions below

0
CommonsWare On BEST ANSWER

If it is determined by the resolution of the Android device's screen

No.

How can I get the default size (in pixels) of a photo which will be captured through Android camera

There is no "default size... of a photo".

If you are using the android.hardware.Camera or android.hardware.camera2 APIs yourself, you need to specify the resolution that you want, from the available resolutions.

If you are using ACTION_IMAGE_CAPTURE, the resolution will be based in part on whether you pass EXTRA_OUTPUT or not, but otherwise is up to the camera app. There are thousands of Android device models, shipping with hundreds of different pre-installed camera apps, and there are many other camera apps available through distribution channels like the Play Store. They will be using the android.hardware.Camera or android.hardware.camera2 APIs, and they will choose what resolution they want to use, by whatever algorithm they want.

5
SaravInfern On

you can do like this

String pickedImagePath = "path/of/the/selected/file";
BitmapFactory.Options bitMapOption=new BitmapFactory.Options();
bitMapOption.inJustDecodeBounds=true;
BitmapFactory.decodeFile(pickedImagePath, bitMapOption);
int imageWidth=bitMapOption.outWidth;            
int imageHeight=bitMapOption.outHeight;

Update:

you can use display metrics to get your screen with

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

int width = metrics.widthPixels;
int height = metrics.heightPixels;

Note: The resolution of your screen and resolution of camera may not be the same. please refer the answer here.

0
NXA On

Get the screen size using the following snippet. this means the current Activity context.

WindowManager windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
int screenWidth = displayMetrics.widthPixels;
int screenHeight = displayMetrics.heightPixels;