My Android camera Uri is returning a null value, but the Samsung fix is in place, help?

Your activity gets destroyed during the Camera activity operation and re-created afterwards. You should use onSaveInstanceState/onRestoreInstanceState mechanism in your activity to preserve the image URI (and any other data) upon the activity restarts. Like this: @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (mImageUri != null) { outState.putString(“cameraImageUri”, mImageUri.toString()); } } @Override protected void onRestoreInstanceState(Bundle … Read more

Camera in Android, how to get best size, preview size, picture size, view size, image distorted

Most often, but not always, there is correspondence between picture aspect ratios and preview aspect ratios. You can be assured that at least some of them are classic 4:3 ratios (e.g. 640×480). Support for 16:9 is also widely available. The screen may have different aspect ratio. To fill it with a camera image correctly, it … Read more

Activity killed / onCreate called after taking picture via intent

Actually the camera causes the orientation change in your activity that is why your activity is being destroyed and recreated. Add this in your manifest file it will prevent the orientation change and your activity will not get destroyed and recreated. <activity android:name=”.YourActivity” android:configChanges=”orientation|keyboardHidden|screenSize” android:screenOrientation=”portrait” > </activity>

Force a camera to always open in portrait mode in android [duplicate]

Try it – private void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; … Read more

Nexus 5x reverse landscape sensor fix in a android camera preview app

The 5X camera is not “reverse”; it does report the correct camera orientation in its parameters, so no special workarounds are needed, just make sure you’re setting the display orientation correctly: public static void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); int degrees … Read more

setRotation(90) to take picture in portrait mode does not work on samsung devices

I try to answer this in relation to the Exif tag. This is what I did: Bitmap realImage = BitmapFactory.decodeStream(stream); ExifInterface exif=new ExifInterface(getRealPathFromURI(imagePath)); Log.d(“EXIF value”, exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase(“6”)){ realImage=ImageUtil.rotate(realImage, 90); }else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase(“8”)){ realImage=ImageUtil.rotate(realImage, 270); }else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase(“3”)){ realImage=ImageUtil.rotate(realImage, 180); } The ImageUtil.rotate(): public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = … Read more

Android open camera from button

To call the camera you can use: Intent intent = new Intent(“android.media.action.IMAGE_CAPTURE”); startActivity(intent); The image will be automatically saved in a default directory. And you need to set the permission for the camera in your AndroidManifest.xml: <uses-permission android:name=”android.permission.CAMERA”> </uses-permission>

broadcast receiver won’t receive camera event

I solved this but by using a different method. Instead of using a broadcast receiver I set up a fileobserver on separate folders that the camera saved to. It’s not as practical as the other way, but it still works fine. Here’s how I set it up: FileObserver observer = new FileObserver(android.os.Environment.getExternalStorageDirectory().toString() + “/DCIM/100MEDIA”) { … Read more

How to capture image from custom CameraView in Android?

try to use Surface View for creating dynamic camera view and set in your required portion. following code try variables set Class level (Global) Button btn_capture; Camera camera1; SurfaceView surfaceView; SurfaceHolder surfaceHolder; public static boolean previewing = false; Following code in onCreate() method getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = new SurfaceView(this); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); btn_capture = … Read more