title: Take photo in Android app and save it into gallery
body: <p>I am developing an Android app, and at some point I have to take a photo and save it to the gallery. The camera opens and takes the photo but does not save it to the gallery.
  Here is my code:</p>
  
  <pre><code>public class CameraActivity extends AppCompatActivity {
  
      @RequiresApi(api = Build.VERSION_CODES.M)
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_camara);
          dispatchTakePictureIntent();
      }
  
      static final int REQUEST_IMAGE_CAPTURE = 1;
  
      @RequiresApi(api = Build.VERSION_CODES.M)
      private void dispatchTakePictureIntent() {
  
  
          if (checkSelfPermission(Manifest.permission.CAMERA)
                  != PackageManager.PERMISSION_GRANTED) {
              requestPermissions(new String[]{Manifest.permission.CAMERA},
                      MY_CAMERA_REQUEST_CODE);
          }
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
              startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
          }
      }
  
  
      private static final int MY_CAMERA_REQUEST_CODE = 100;
  
  
      @Override
  
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  
          if (requestCode == MY_CAMERA_REQUEST_CODE) {
  
              if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  
                  Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show();
  
              } else {
  
                  Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show();
  
              }
  
          }
      }
  }
  </code></pre>
  
  <p>Layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".CameraActivity"&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  
  <p>Can anyone help me? I've searched other similar questions but neither could help me.
  Thanks to everyone, and rest of a good day.</p>