So, I am working on a project related to the camera, and I tested it on many devices, and they all passed the tests, with the exception of Nexus 10.
I canβt understand what is happening and no one is talking about a problem on the Internet.
I was able to reproduce the problem on two different Nexus 10 (wifi) devices.
Here is my activity 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();
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 are no error messages and the screen is just black

android samsung-mobile android-camera android-4.2-jelly-bean nexus-10
Mr. Me
source share