Captured video being saved to different folder than specified - android

I'm making an app that let's you either capture photo/video, or choose an existing photo/video before sending. I set up the directory to save the files in here:
String appName = Main.this.getString(R.string.app_name);
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_PICTURES), appName);
and I name the files here
File mediaFile;
Date now = new Date();
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(now);
String path = mediaStorageDir.getPath() + File.separator;
if(mediaType == MEDIA_TYPE_PHOTO){
mediaFile = new File(path + "IMG_" + timestamp + ".jpg");
} else if(mediaType==MEDIA_TYPE_VIDEO){
mediaFile = new File(path + "VID_" + timestamp + ".mp4");
}
So it's saving my pictures under /storage/emulated/0/pictures/(app name) with correct timestamped format. However, my videos are being saved to /storage/emulated/0/DCIM/100MEDIA and are just being named VIDEO0073, VIDEO00074, etc. I tried changing the directory name to MOVIES instead of PICTURES or DCIM, but there is no effect. I'm on an HTC One running Android 4.3

This is a bug that occurs on certain devices including the HTC One. If you include your code where you declare your video Intent I could more precisely answer the question, but basically, after you declare your Intent for the video (not image), get your Uri like so:
videoUri = getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, new ContentValues());
In this case the video will be saved in the /storage/emulated/0/video folder instead of the pictures or dcim folders you mentioned above.

Related

Saving photo in different location

In my app, I need to take a photo, then send it via RestApi with other data. I want to store this photo in a different location to process it in the future. My code:
private void TakePictureAfterScan() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
TAKEN_PHOTO = Uri.fromFile(getOutputMediaFile());
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, TAKEN_PHOTO);
startActivityForResult(takePictureIntent, ACTIVITY_CODE_REQUEST_IMAGE_CAPTURE);
}
private static File getOutputMediaFile() {
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), PICTURE_PHOTO_DIR);
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return new File(mediaStorageDir.getPath() + File.separator +
"IMG_" + timeStamp + ".jpg");
}
When I set a breakpoint in 'onActivityResult' method (which is empty right now for tests), there are already two .jpg files saved in the device:
In DCIM/Camera folder
In my temporary folder
The problem is, both files have different names. I do not need and do not want files from DCIM/Camera folder. Is there any simple way to save taken a photo only in my temporary folder?
instead of this .
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), PICTURE_PHOTO_DIR);
use this..
File mediaStorageDir = new File(Environment.getExternalStorageDirectory().toString() + "folder name" + ImageName;);

In MI device image name automatic change

In Mi device when i captured image from my custom camera image save perfectly to sdcard but after few minutes image name automatic change
For save image in sdcard i have used below code
java.util.Date date = new java.util.Date();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(date.getTime());
file = new File(file.getAbsolutePath() + File.separator
+ "IMG_"
+ timeStamp
+ ".jpg");
image name save as in sdcard with following format :
IMG_1601464_142653.jpg
After few minutes image name change with IMG_1601464_142653_152145632141214.jpg
i don't know from where _152145632141214 this line is added at last of image name in MI device

Deleting Video File in Android

I want to the delete the file after compression is done. I have used the code to delete the file. But when I check in the Gallery the video file is still there but it doesn't play shows error Media not Supported. Here is my code.
if (compressed) {
snackbar = TSnackbar
.make(coordinatorLayout,"Video Compressed Successfully",TSnackbar.LENGTH_SHORT);
snackbar.show();
//Delete File from Location.
File videoFile = new File(mediaFile.getPath());
if(videoFile.exists())
{
boolean del = videoFile.delete();
}
}
This is mediaFile
mediaFile = new File(path + "VID_" + timestamp + ".mp4");
This is the storage directory
File mediaStorageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
appName);
Try this
getContentResolver().delete(Uri.parse(mediafile.getPath()),null,null);

Photo not saved in location given

I am trying to take a picture in my app, and then redisplay it. When I start the camera intent, I pass a URI to save the photo location in. Here is how I create the file:
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String imageFileName = "Waypoint_photo_" + timeStamp + ".jpg";
File storageDir = new File(PICTURE_FOLDER);
storageDir.mkdirs();
Log.v("FILE", String.format("New file: %s%s%s", PICTURE_FOLDER, File.separator, imageFileName));
return new File(storageDir, imageFileName);
Where picture folder is:
public static final String PICTURE_FOLDER = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString() + File.separator + "UtopiaWaypoints";
This creates a file similar to:
/storage/emulated/0/Pictures/UtopiaWaypoints/Waypoint_photo_20150718_102116.jpg
In my onActivityResult, I get the file from the same path, and create a thumbnail version of it. At this point if I look on the device I see the files, but they are in /mnt/shell/emulated/0/Pictures/UtopiaWaypoints:
shell#shamu:/mnt/shell/emulated/0/Pictures/UtopiaWaypoints $ ls
Waypoint_photo_20150718_102825.jpg
Waypoint_photo_20150718_102825.png
shell#shamu:/mnt/shell/emulated/0/Pictures/UtopiaWaypoints $ pwd
/mnt/shell/emulated/0/Pictures/UtopiaWaypoints
On my device (nexus 6), /storage/emulated exists (neither is a symbolic link), but it only contains a "legacy" folder.
So when I try to load the file later from the /storage/emulated directory (which is what the Environment.PICTURE_DIRECTORY returns, the app can't find the file.
// This line outputs something similar to: /storage/emulated/0/Pictures/UtopiaWaypoints/Waypoint_photo_20150718_1042581116411973.png
Log.v("WPA", String.format("Loading thumbnail from: %s", Utils.getFullThumbnailPath(wayPoint.getPicture())));
Bitmap imageBitmap = BitmapFactory.decodeFile(Utils.getFullThumbnailPath(wayPoint.getPicture()));
wayPointImageView.setImageBitmap(imageBitmap);
The second to the last line (decodeFile) shows this in the log:
D/skia﹕ --- SkImageDecoder::Factory returned null
imageBitmap is null and the ImageView is blank.
What am I doing wrong?

Android - Get file with path

I would like to know how to get a file from its name.
I use the camera to take a photo. It saved the photo with this:
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
And now (after closing and opening again the app), I would like to get the file or Uri from the name of the picture (I saved it in a string (timeStamp)) to a preview.
Sorry for my english.

Categories

Resources