Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:22:24+00:00 2026-06-12T20:22:24+00:00

I have a strange issue in my camera app when tested with galaxy nexus..It

  • 0

I have a strange issue in my camera app when tested with galaxy nexus..It simply crash when try to start the camera activity..But it works fine with almost all other devices..
These are my functions…..

@Override
public void surfaceCreated(SurfaceHolder holder) {
 // TODO Auto-generated method stub

     try {
        camera = Camera.open();
        camera.setPreviewDisplay(holder);

    Camera.Parameters parameters = camera.getParameters();
        if (Integer.parseInt(Build.VERSION.SDK) >= 8)
            setDisplayOrientation(camera, 90);
        else
            parameters.set("orientation", "portrait");
        parameters.setPictureFormat(PixelFormat.JPEG);
        camera.setParameters(parameters);



    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 


}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
  int height) {
 // TODO Auto-generated method stub
 if(previewing){
  camera.stopPreview();
  previewing = false;
 }

 if (camera != null){
  try {


   camera.setPreviewDisplay(surfaceHolder);
   camera.startPreview();
   previewing = true;
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}

Can anyone help
me ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:22:25+00:00Added an answer on June 12, 2026 at 8:22 pm

    finally i got the answer..Nexus has both front and back end cameras.So the problem was the code which used to open the camera(need to set the camera id for the front end camera) and also we need to set the appropriate preview size..Here is the modified code..

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
      int height) {
    
    
    
        List<Size> sizes = parameters.getSupportedPreviewSizes();
        Size optimalSize = getOptimalPreviewSize(sizes, width, height);
        parameters.setPreviewSize(optimalSize.width, optimalSize.height);
    
        camera.setParameters(parameters);
        camera.startPreview();
         startPreview();
    
    }
    
    
       @Override
    public void surfaceCreated(SurfaceHolder holder) {
    
    
         try {
    
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
                  Camera.CameraInfo info=new Camera.CameraInfo();
    
                  for (int i=0; i < Camera.getNumberOfCameras(); i++) {
                    Camera.getCameraInfo(i, info);
    
                    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                      camera=Camera.open(i);
                      defaultCameraId = i;
                    }
                  }
                }
    
                if (camera == null) {
                  camera=Camera.open();
                }
    
    
    
    
                try {
                    camera.setPreviewDisplay(surfaceHolder);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    
                Camera.Parameters parameters = camera.getParameters();
                android.hardware.Camera.CameraInfo info =
                        new android.hardware.Camera.CameraInfo();
                android.hardware.Camera.getCameraInfo(defaultCameraId, info);
                int rotation = this.getWindowManager().getDefaultDisplay()
                        .getRotation();
                if (Integer.parseInt(Build.VERSION.SDK) >= 8)
                {
    
                     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;
                     }
                     int result;
                     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                         result = (info.orientation + degrees) % 360;
                         result = (360 - result) % 360;  
                     } else {  // back-facing
                         result = (info.orientation - degrees + 360) % 360;
                     }
                     camera.setDisplayOrientation(result);
    
                }
                else
                {
                    parameters.set("orientation", "portrait");
                }
    
    
                camera.setParameters(parameters);
    
    
    
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    
    
    }
    
    
        private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
                    final double ASPECT_TOLERANCE = 0.1;
                    double targetRatio = (double) w / h;
                    if (sizes == null) return null;
    
                    Size optimalSize = null;
                    double minDiff = Double.MAX_VALUE;
    
                    int targetHeight = h;
    
    
                    for (Size size : sizes) {
                        double ratio = (double) size.width / size.height;
                        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
                        if (Math.abs(size.height - targetHeight) < minDiff) {
                            optimalSize = size;
                            minDiff = Math.abs(size.height - targetHeight);
                        }
                    }
    
    
                    if (optimalSize == null) {
                        minDiff = Double.MAX_VALUE;
                        for (Size size : sizes) {
                            if (Math.abs(size.height - targetHeight) < minDiff) {
                                optimalSize = size;
                                minDiff = Math.abs(size.height - targetHeight);
                            }
                        }
                    }
                    return optimalSize;
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange issue with a MVC 3 app running as an Azure
I have a strange issue . I am currently working on a mail app
I have a strange issue in my GWT app. My application is working fine
I have strange issue. My application have multiple activitys, on one activity is setting
Have following strange issue, have 7 lines (same classes) but after 2 lines it's
I have very strange issue. In my WP7 app I have a pivot control
I have strange issue with nested left-joins in postgresql... It's hard to explain, but
I have strange issue. ModelState has error. But I don`t have a rule for
I have a strange issue. I created a simple app in haskell with sdl,
I have a strange issue with to_json method in my Rails 3 app. (well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.