Nexus 10, Front facing camera Preview is black (no preview)

Mr.Me

So I'm working on a Camera related project, and I've been testing it on many devices and all of them passed the tests except for the Nexus 10.

I can't really figure out what is going on, and there is no one talking about the issue online.

I was able to replicate the issue on two different Nexus 10 (wifi) devices.

Here is my activity's code:

public class MainActivity extends Activity {
    private static Camera mCamera;
    private static boolean mCameraOpen;
    private static ImageView mPreviewImageView;
    private SurfaceView mPreviewSurfaceView;
    private static boolean mPreviewRunning;
    private static Handler mHandler;
    private static int TESTS_COUNT = 0;
    private Camera.Parameters mCameraParameters;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mHandler = new Handler();
        mPreviewSurfaceView = (SurfaceView) findViewById(R.id.surfaceview);
        mPreviewImageView = (ImageView) findViewById(R.id.imageview);
        mPreviewSurfaceView.getHolder().addCallback(mCallback);

        TextView view = (TextView) findViewById(R.id.textview);
        view.setText("Format: " + String.valueOf(TESTS_COUNT));

    }

    @Override
    public void onResume(){
        super.onResume();
        if (mCamera == null){
            for (int i = 0; i < Camera.getNumberOfCameras(); i++){
                Camera.CameraInfo info = new Camera.CameraInfo();
                Camera.getCameraInfo(i, info);

                if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT){
                    mCamera = Camera.open(i);
                    Camera.Parameters params = mCamera.getParameters();
                    params.set("camera-id", 2);
                    List<Integer> formats = params.getSupportedPreviewFormats();
                    if (formats.size() > TESTS_COUNT) {
                        Log.e("Camera", "testing preview format at index: " + TESTS_COUNT);
                        params.setPreviewFormat(formats.get(TESTS_COUNT));
                        mCamera.setParameters(params);
                        mCameraOpen = true;
                        SurfaceHolder holder = mPreviewSurfaceView.getHolder();
                        if (holder != null && holder.getSurface() != null && holder.getSurface().isValid()) {
                            mCallback.surfaceCreated(holder);
                        }
                        mCameraParameters = params;
                        break;
                    } else {
                        finish();
                    }
                }

            }
        }
    }

    @Override
    public void onPause(){
        super.onPause();
        if (mPreviewRunning){
            mCamera.stopPreview();
            mCamera.setPreviewCallback(null);
            mPreviewRunning = false;
        }

        if (mCameraOpen){
            mCamera.release();
            mCamera = null;
            mCameraOpen = false;
        }
    }

    @Override
    public void onDestroy(){
        super.onDestroy();

    }

    private final SurfaceHolder.Callback mCallback =  new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder surfaceHolder) {
                if (mCameraOpen && mCamera != null){
                    try {
                        mCamera.setPreviewDisplay(surfaceHolder);
                        mCamera.setPreviewCallback(new Camera.PreviewCallback() {
                            private int count;
                            private int total;
                            @Override
                            public void onPreviewFrame(byte[] bytes, Camera camera) {
                                if (count == 15){
                                    Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
                                    // pWidth and pHeight define the size of the preview Frame
                                    ByteArrayOutputStream out = new ByteArrayOutputStream();

                                    // Alter the second parameter of this to the actual format you are receiving
                                    YuvImage yuv = new YuvImage(bytes, ImageFormat.NV21, previewSize.width, previewSize.height, null);

                                    // bWidth and bHeight define the size of the bitmap you wish the fill with the preview image
                                    yuv.compressToJpeg(new Rect(0, 0, previewSize.width, previewSize.height), 50, out);
                                    byte[] bitmapBytes = out.toByteArray();
                                    final Bitmap bitmap= BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length);
                                    mHandler.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            mPreviewImageView.setImageBitmap(bitmap);
                                        }
                                    });
                                    count = 0;
                                    total++;
                                    if (total > 5){
                                        TESTS_COUNT++;
                                        if (TESTS_COUNT == mCameraParameters.getSupportedPreviewSizes().size()) {
                                            finish();
                                            return;
                                        }
                                        Intent intent = new Intent( MainActivity.this, MainActivity.class);
                                        startActivity(intent);

                                    }

                                } else {
                                    count++;
                                }

                            }
                        });

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
        }

        @Override
        public void surfaceChanged(SurfaceHolder surfaceHolder,  int format, int width, int height) {
            for (Camera.Size size : mCameraParameters.getSupportedPreviewSizes()){
                if (size.width == width && size.height == height){
                    if (mCameraOpen && mCamera != null && mPreviewRunning == false) {
                        mCameraParameters.setPreviewSize(width, height);
                        mCamera.setParameters(mCameraParameters);

                        mCamera.startPreview();

                        mPreviewRunning = true;
                        break;
                    }
                }
            }
            if (mPreviewRunning == false){
                Log.e("CameraPreview", "size not supported");
            }

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder surfaceHolder) {

        }
    };

}

My layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context=".MainActivity"
    android:orientation="vertical"
    android:weightSum="2">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello"/>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context=".MainActivity"
    android:orientation="horizontal"
    android:layout_weight="1"
    android:weightSum="2">
        <SurfaceView
            android:layout_width="640px"
            android:layout_height="480px"
            android:id="@+id/surfaceview"/>
        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:id="@+id/imageview"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textview"
            android:textSize="40sp"/>
</LinearLayout>
</LinearLayout>

and manifest :

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

There is no error messages and the screen is just black

Screenshot

Jorch914

Please verify your device by using an app called CtsVerifier, this app is included in the Android Open Source Project and is part of the Compatibility test suite for android devices(CTS). CTS Verifier have a series of tests that check the camera.check this link

You can be sure that if the front camera does not work within this app. Then your device is probably damaged, or some corruption has occurred on the hal layer. If that is the case you may attempt to downgrade/upgrade your android os. If not it probably is hardware damage.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Glass camera preview display is garbled

From Dev

Android Camera Preview Stretched

From Dev

Android Camera preview on two views ( Multi-lenses camera preview )

From Dev

Capture camera and show preview in div

From Dev

ImageView Camera preview

From Dev

Android Camera preview in a fragment

From Dev

Taking a ScreenShot of SurfaceView with Camera Preview in it

From Dev

Custom camera shows dark picture preview when photo taken on Nexus

From Dev

Android camera preview is dark

From Dev

PBJVision switch to front facing camera

From Dev

Change contrast in Camera Preview - Android

From Dev

Why is camera preview not working

From Dev

Camera Preview and OCR

From Dev

Camera preview is black when using getExternalStorageDirectory to save the video

From Dev

Tango Camera Preview for RGBIR

From Dev

Auto focus camera without preview

From Dev

ovr camera rotating in the preview

From Dev

Camera Preview Stretched on Front Facing Camera

From Dev

Camera preview is fine but front camera produces very dark photos

From Dev

Android Camera preview on two views ( Multi-lenses camera preview )

From Dev

Surface View Camera Preview

From Dev

Stretched camera preview on Android

From Dev

Skewing the SurfaceView of the Camera Preview

From Dev

Android background camera preview

From Dev

image distorted on camera preview

From Dev

Camera Preview Stretched on Front Facing Camera

From Dev

Nexus 5x Frames from preview are turned Camera2

From Dev

Display camera preview in a circle

From Dev

Opening the front facing camera