Save Video SD Card - android

Hello How I can Save Video On external card I have android 4.4.2
File folder = new File(Environment.getExternalStorageDirectory() + "/Output");
if (!folder.exists()) folder.mkdir();
String out = Environment.getExternalStorageDirectory() + "/Output/" +
DateFormat.format("yyyy-MM-dd_kk-mm-ss", new Date().getTime()) +
".mp4";

Related

How to create Folder directory in Android API 30 or Android R version device

File file = new File(MATTApplication.getContext().getExternalFilesDir(
Environment.DIRECTORY_DOCUMENTS), "MATT_LOGS");//new File(Environment.getExternalStorageDirectory(), "MATT_LOGS");
if (!file.mkdirs()) {
//file.mkdir();
file.mkdirs();
}
filePath = file.getAbsolutePath() + File.separator + fileName;

Android: Creating folder does not work

I Want to take a photo and save it in the external storage, but the folder creation fails.
Permission is set.
File folder = new File(Environment.getExternalStorageDirectory() +
File.separator + "DCIM" + File.separator + "ScannerApp");
if(!folder.exists()){
folder.mkdirs();
}
Help please :)
use this code below to initialize folder value:
File folder = new File(Environment.getExternalStorageDirectory(), "DCIM" + File.separator + "ScannerApp");
or
File folder = new File(new File(Environment.getExternalStorageDirectory(), "DCIM"), "ScannerApp");
Replace this
File folder = new File(Environment.getExternalStorageDirectory() +
File.separator + "DCIM" + File.separator + "ScannerApp");
if(!folder.exists()){
folder.mkdirs();
}
with
File folder = new File(Environment.getExternalStorageDirectory().getPath() +
File.separator + "DCIM" + File.separator + "ScannerApp");
if(!folder.exists()){
folder.mkdirs();
}
The problem is that you are using Environment.getExternalStorageDirectory() which will not return the path. Use Environment.getExternalStorageDirectory().getPath() to get the path.
Hope this helps.

png transparent image file in android

I want to save a png image to SD card and it should be without background.
in the sd card I do not see any background but when attach it into telegram I see a white background. here is my code in android:
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/background_eraser/");
dir.mkdirs();
mImagename = "image" + cal.getTimeInMillis() + ".png";
file = new File(dir, mImagename);

Creating directory hierarchy in Android (for gallery)

I have some code like this:
photo = new File(android.os.Environment.getExternalStorageDirectory(), "images/mydir/" + File.separator + timeStamp + ".jpg");
photo.getParentFile().mkdirs();
photo.createNewFile();
But in the gallery, I'm only seeing "mydir" with the photos inside it. No "images" directory to be found.
How do I create a hierarchy so there's an image folder and mydir is inside that?
Thanks
You have problem in your code as you have one / after mydir and you are also adding File.separator so final output will be images/mydir//
photo = new File(android.os.Environment.getExternalStorageDirectory(), "images/mydir/" + File.separator + timeStamp + ".jpg");
Just remove the / after mydir like below
photo = new File(android.os.Environment.getExternalStorageDirectory(), "/images/mydir" + File.separator + timeStamp + ".jpg");
This should work now.

android programming question

dy_path = Environment.getExternalStorageDirectory() + "\5.jpg";
Instead of that i want how to give dynamic path automatically picture saved based on current time.
I am new to Android. Plz answer my question
You could concatenate the path with
DateFormat.getDateInstance().format(new Date());
That is, use something like
String time = DateFormat.getDateInstance().format(new Date());
dy_path = Environment.getExternalStorageDirectory() + "\\" + time + "\\5.jpg";
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath() + "/your folder name" + File.separator);
dir.mkdirs();
String pic = CommonMethod.getRandomString(30);
File file = new File(dir, String.valueOf(pic + ".jpg"));
picturePath = picturePath + String.valueOf(pic) + ".jpg";

Categories

Resources