title: Accessing Camera and Stores Images Marshmallow
body: <p>I have this code which allows users to access the camera to take photos and select images from gallery, it works on my Sony Xperia Z3 running Android 5.1.1.</p>
  
  <p>I now have upgraded to a Nexus 5X running Android 6.0, but when i try to use the camera or save an image i get errors any help?</p>
  
  <p>My Code to use Camera</p>
  
  <pre><code>Intent CameraImage = new Intent("android.media.action.IMAGE_CAPTURE");
  Intent SelectedCameraImage = Intent.createChooser(CameraImage, "Take A Photo With");
  startActivityForResult(SelectedCameraImage, SELECTED);
  </code></pre>
  
  <p>My Result Handler</p>
  
  <pre><code>public void onActivityResult(int RequestCode, int ResultCode, Intent Data) {
      if (ResultCode == RESULT_OK) {
          if (RequestCode == SELECTED) {
              Uri SelectedImageUri = Data.getData();
              SelectedImagePath = getPath(SelectedImageUri);
              Log.d("DatabaseOperations", "Image Path :  " + SelectedImagePath);
              Img.setImageURI(SelectedImageUri);
  
              try {
                  FileInputStream FileInpStream = new FileInputStream(SelectedImagePath);
                  BufferedInputStream BufInputStream = new BufferedInputStream(FileInpStream);
                  DBByte = new byte[BufInputStream.available()];
                  BufInputStream.read(DBByte);
                  Log.d("DatabaseOperations", "Image Size :  " + DBByte.length + " KB");
              }
  
              catch (IOException e) {
                  Log.d("DatabaseOperations", "Error :  " + SelectedImagePath);
                  Log.d("DatabaseOperations", e.getMessage(), e);
              }
          }
      }
  }
  
  public String getPath(Uri Uris) {
      String[] projection = { MediaStore.Images.Media.DATA };
      Cursor Cursor = managedQuery(Uris, projection, null, null, null);
      int ColumnIndex = Cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      Cursor.moveToFirst();
      return Cursor.getString(ColumnIndex);
  }
  </code></pre>
  
  <p>My Manifest Permissions</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.camera.autofocus" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
  &lt;uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission-sdk-23 android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission-sdk-23 android:name="android.permission.CAMERA" /&gt;
  </code></pre>
  
  <p>The Errors (Logcat)</p>
  
  <pre><code>FATAL EXCEPTION: main
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime: Process: rajancorporations.database, PID: 3768
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity } from ProcessRecord{c9f94d7 3768:rajancorporations.database/u0a80} (pid=3768, uid=10080) with revoked permission android.permission.CAMERA
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:1620)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:1573)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.app.Activity.startActivityForResult(Activity.java:3930)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.app.Activity.startActivityForResult(Activity.java:3890)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at rajancorporations.database.Reg$2.onClick(Reg.java:75)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.view.View.performClick(View.java:5204)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:21153)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  03-01 22:12:44.071 3768-3768/rajancorporations.database E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>