Camera not opening after granting the permission in surface view
<p>I am making a custom camera application. Which requires surface view and opens the camera inside the surface view. 
But when running the same application on marshmallow I am using <code>Runtime permission</code> to grant permission for camera. After I allow the dialog disappears but black screen shows up and camera doesn't get open. 
I have tried also by calling the activity again after allowing but its not working.</p>

<p>THANX in advance.</p>

<pre><code>@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    if (preview) {
        camera.stopFaceDetection();
        camera.stopPreview();
        preview = false;
    }

    if (camera != null) {
        preview = true;
        // Parameters
        Parameters parameters = camera.getParameters();
        parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        List&lt;Camera.Size&gt; sizeList = camera.getParameters().getSupportedPreviewSizes();
        bestSize = sizeList.get(0);
        for (int i = 1; i &lt; sizeList.size(); i++) {
            if ((sizeList.get(i).width * sizeList.get(i).height) &gt;
                    (bestSize.width * bestSize.height)) {
                bestSize = sizeList.get(i);
            }
        }
        parameters.setPictureSize(bestSize.width, bestSize.height);
        camera.setParameters(parameters);
        camera.startPreview();
        camera.startFaceDetection();
        camera.setFaceDetectionListener(faceDetectionListener);
    }
}
@Override
public void surfaceCreated(SurfaceHolder holder) {

    customsurfaceview();
}
public void customsurfaceview() {

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        Log.e("PLAYGROUND", "Permission is not granted, requesting");
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 123);
    }
    Log.e("Entered Surace Created", "----------------");
}
public void SetPreview_onSurface() {
    if (camera == null)
        return;


    camera = Camera.open();
    try {
        camera.setPreviewDisplay(surfaceView.getHolder());
    } catch (IOException e) {
        e.printStackTrace();
        Log.e("printStackTrace", "--" + e.getMessage());

    }
    camera_button = (ImageView) findViewById(R.id.camera_button);
    camera_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (capture_chek == 0) {
                camera.cancelAutoFocus();
                camera.takePicture(shutterCallback, null, pictureCallback);
                capture_chek = 1;
            }
        }
    });
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    if (camera != null) {
        camera.release();
        camera = null;
        preview = false;
    }
}
</code></pre>