In MI device image name automatic change - android

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

Related

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?

Single filename for captured images, overwriting the previous image, i.e.."TestPic.jpg"

Each time I take a photo, I want the image name to be "TestPic.jpg" every time, but every time I click to take a pic, it saves as: TestPic2203 , TestPic4023, etc.
I wrote code to delete the previous image and keep only one image in that folder which is replaced by next picture.
public static File CreateImageFile() throws IOException {
String ImageFileName = "TestPic";
File storageDir = new File(Environment.getExternalStorageDirectory()+"/EasyRecharge");
if(!storageDir.exists()){
File EasyRechargeDir = new File(Environment.getExternalStorageDirectory().getPath()+"/EasyRecharge/");
EasyRechargeDir.mkdirs();
}
File test = new File(Environment.getExternalStorageDirectory().getPath()+"/EasyRecharge/TestPic.jpg");
if(test.exists()){
test.delete();
}
File image = File.createTempFile(ImageFileName,// prefix
".jpg", // suffix
storageDir
);// directory
AppLog.showAppFlow("file created");
AppLog.showAppFlow("image filename:"+image);
return image;
}
If you want the file name to be the same each time, don't use File.createTempFile(). It's purpose is exactly to create a unique name for each file...
Instead use:
File image = new File(storageDir, ImageFileName + ".jpg");
This way, the filename will be the same each time.

Captured video being saved to different folder than specified

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.

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.

Saving image to sd with current date and time in name doesn't work

In my application I use a button to launch Camera application and save picture to specific folder on sdCard naming it by current date and time. When I hardcode the name for the picture, it works fine, but if I'm trying to put date in the name it doesn't work at all.
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), Constants.IMAGE_FOLDER_URI);
imagesFolder.mkdirs();
Date d = new Date();
CharSequence s = DateFormat.format("MM-dd-yy hh:mm:ss", d.getTime());
File image = new File(imagesFolder, s.toString() + ".jpg"); //this line doesn't work
Uri uriSavedImage = Uri.fromFile(image);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivity(imageIntent);
If I put:
s = "some_name";
then it works, but I need current date and time in image name.
Colon : is not a valid character in a file name, that is why it is failing to create such a file.
Try change your name pattern to something like this:
CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
Put this code and try:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HH_mm_ss");
String currentTimeStamp = dateFormat.format(new Date());
Here is an alternate solution:
File cameraFolder;
if (android.os.Environment.getExternalStorageState().equals
(android.os.Environment.MEDIA_MOUNTED))
cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),
"YOUR_FOLDER_NAME/");
else
cameraFolder= StatusUpdate.this.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(),
"YOUR_FOLDER_NAME/" + imageFileName);
If you want just the TimeStamp as the image name, you can remove "picture_" + from the String imageFileName.
use this
File image = new File(imagesFolder, s+ "Rj.jpg");

Categories

Resources