title: ERROR: failed to connect to camera service @ Android marshmallow
body: <p>Im trying to build a camera app (Im pretty new at this)
  When I run the application on real device its gives me this Error:</p>
  
  <pre><code>    05-26 13:16:37.504 14076-14076/involved.pose9 E/AndroidRuntime: FATAL EXCEPTION: main
                                                              Process: involved.pose9, PID: 14076
                                                              java.lang.RuntimeException: Fail to connect to camera service
                                                                  at android.hardware.Camera.&lt;init&gt;(Camera.java:511)
                                                                  at android.hardware.Camera.open(Camera.java:368)
                                                                  at involved.pose9.CameraActivity.surfaceCreated(CameraActivity.java:63)
                                                                  at android.view.SurfaceView.updateWindow(SurfaceView.java:582)
                                                                  at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:177)
                                                                  at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
                                                                  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
                                                                  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
                                                                  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060)
                                                                  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                  at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                                  at android.view.Choreographer.doFrame(Choreographer.java:606)
                                                                  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                                  at android.os.Handler.handleCallback(Handler.java:746)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                  at android.os.Looper.loop(Looper.java:148)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  </code></pre>
  
  <p>This is my Class</p>
  
  <pre><code>    import android.graphics.PixelFormat;
      import android.hardware.Camera;
      import android.support.v7.app.AppCompatActivity;
      import android.os.Bundle;
      import android.view.SurfaceHolder;
      import android.view.SurfaceView;
      import android.view.Window;
      import android.view.WindowManager;
  
      import java.io.IOException;
  
      public class CameraActivity extends AppCompatActivity implements SurfaceHolder.Callback {
  
  SurfaceHolder mSurfaceHolder;
  SurfaceView mSurfaceView;
  public Camera mCamera;
  boolean mPreviewRunning;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      getWindow().setFormat(PixelFormat.TRANSLUCENT);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.activity_camera);
      mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
      mSurfaceHolder = mSurfaceView.getHolder();
      mSurfaceHolder.addCallback(this);
      mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  }
  
  @Override
  public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
      // TODO Auto-generated method stub
  
  
      if (mPreviewRunning) {
          mCamera.stopPreview();
      }
      Camera.Parameters p = mCamera.getParameters();
      //p.setPreviewSize(w, h);
      mCamera.setParameters(p);
      try {
          mCamera.setPreviewDisplay(arg0);
      } catch (IOException e) {
          e.printStackTrace();
      }
      mCamera.startPreview();
      mPreviewRunning = true;
  }
  
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
      // TODO Auto-generated method stub
      mCamera = Camera.open();
  }
  
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
      // TODO Auto-generated method stub
      mCamera.stopPreview();
      mPreviewRunning = false;
      mCamera.release();
  }
  
  Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
      public void onPictureTaken(byte[] imageData, Camera c) {
      }
  };
  }
  </code></pre>
  
  <p>What is wrong here? Thanks in advance..</p>
  
  <p>I also declare permissions in manifest.xml</p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  &lt;uses-feature android:name="android.hardware.Camera" /&gt;
  &lt;uses-feature android:name="android.hardware." /&gt;
  </code></pre>