0

In my application the user can upload a photo to server by either choosing an existing one or taking a new one. When taking a new one I have the following code:

// Take a new photo
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File cameraFolder;

if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
    cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(), "images/");
} else {
    cameraFolder = getCacheDir();
}

if (!cameraFolder.exists()) {
    cameraFolder.mkdirs();
}

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
String timeStamp = dateFormat.format(new Date());
String imageFileName = "picture_" + timeStamp + ".jpg";

File photo = new File(Environment.getExternalStorageDirectory(), "images/" + imageFileName);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
pictureUri = Uri.fromFile(photo);

startActivityForResult(takePictureIntent, ACTION_REQUEST_CAMERA);

The problem with above code is that the photo is not saved to the gallery which I need. How do I get the user to take a photo and have it saved and submit to my server?

KVISH
  • 12,923
  • 17
  • 86
  • 162
  • https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl – CommonsWare Dec 12 '16 at 22:31
  • Can you add more insight? I tried the mediascanner, but doesn't seem to have an affect. – KVISH Dec 12 '16 at 22:39
  • Well, I don't know what "saved to the gallery" means. My assumption is that you mean "shows up in a gallery app". In that case, we have to guess how your gallery app behaves. Many use `MediaStore` to determine the available photos. In that case, `MediaScannerConnection` gets your requested photo added to the `MediaStore`. But, I don't know if there is a bug in how you used `MediaScannerConnection`, whether your gallery app reacts to changes in the `MediaStore` in real time, and whether any of this pertains to what you mean by "saved to the gallery". – CommonsWare Dec 12 '16 at 22:41

0 Answers0