title: Generate own app album to save images from camera just like Messenger and Whatsapp app
body: <p>I would like to generate dedicated album for my application in gallery when users capture photos using camera in my application. This album will used to save all images that captured from camera intent inside my application. It works just like the Messenger and Whatsapp app. Anyone know how to do this?</p>
  
  <pre><code>public class ImageQueryActivity extends AppCompatActivity {
  
      private LinearLayout mImageQueryLayout;
      private ImageView mAddPhotoButton;
      private String mCurrentPhotoPath;
  
      final int REQUEST_IMAGE_CAPTURE = 1;
      static final int REQUEST_GALLERY = 2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_image_query);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  dispatchTakePictureIntent();
              }
          });
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          mImageQueryLayout = (LinearLayout) findViewById(R.id.image_query_layout);
          mAddPhotoButton = (ImageView) findViewById(R.id.add_photo_image_view);
          mAddPhotoButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  dispatchTakePictureIntent();
              }
          });
      }
  
      // dp to pixel converter
      public static int convDpToPx(Context context, float dp) {
          DisplayMetrics metrics = context.getResources().getDisplayMetrics();
          return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
      }
  
      private File createImageFile() throws IOException {
          // Create an image file name
          String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
          String imageFileName = "JPEG_" + timeStamp + "_";
          File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
          File image = File.createTempFile(
                  imageFileName,  /* prefix */
                  ".jpg",         /* suffix */
                  storageDir      /* directory */
          );
  
          // Save a file: path for use with ACTION_VIEW intents
          mCurrentPhotoPath = image.getAbsolutePath();
          return image;
      }
  
      private void dispatchTakePictureIntent() {
          AlertDialog.Builder builder = new AlertDialog.Builder(ImageQueryActivity.this);
          builder.setPositiveButton("Camera", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                  if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                      File photoFile = null;
                      try {
                          photoFile = createImageFile();
                      } catch (IOException ex) {
                          Toast.makeText(getApplicationContext(),
                                  "Problem occurred while saving photo",
                                  Toast.LENGTH_LONG).show();
                      }
                      if (photoFile != null) {
                          Uri photoURI = FileProvider.getUriForFile(getApplicationContext(),
                                  "com.kelvin.foodizzy.fileprovider",
                                  photoFile);
                          takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                          startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
                          galleryAddPic(mCurrentPhotoPath);
                      }
                  }
              }
          });
          builder.setNegativeButton("Gallery", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  Intent intent = new Intent();
                  intent.setType("image/*").setAction(Intent.ACTION_GET_CONTENT);
                  startActivityForResult(Intent.createChooser(intent, "Select File"), REQUEST_GALLERY);
              }
          });
          builder.show();
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (resultCode == RESULT_OK) {
              if (requestCode == REQUEST_IMAGE_CAPTURE) {
                  ImageView imageView = new ImageView(this);
                  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams
                          (LinearLayout.LayoutParams.MATCH_PARENT,
                                  convDpToPx(getApplicationContext(), 180));
                  layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin,
                          layoutParams.rightMargin, convDpToPx(getApplicationContext(), 20));
                  imageView.setLayoutParams(layoutParams);
                  imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                  imageView.setImageBitmap(BitmapFactory.decodeFile(mCurrentPhotoPath));
                  galleryAddPic(mCurrentPhotoPath);
                  mImageQueryLayout.addView(imageView);
              }
          }
      }
  
      private void galleryAddPic(String file) {
          Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
          File f = new File(file);
          Uri contentUri = Uri.fromFile(f);
          mediaScanIntent.setData(contentUri);
          sendBroadcast(mediaScanIntent);
      }
  
  }
  </code></pre>