I am developing my first Android application, and I had a problem trying to create a directory for saving recorded video files.
I have a method in my main action buttonOnClickRecordthat causes the intention to use an Android camera, I also create a file during this method call, and I call a method mkdirs()on it to create a directory to store the file.
I also implemented <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />in my manifest.
public void buttonOnClickRecord(View v){
mediaFile =
new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/NewDirectory/myvideo.mp4");
mediaFile.mkdirs();
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
Uri videoUri = Uri.fromFile(mediaFile);
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
Toast.makeText(this, "Video saved to:\n" +
data.getData(), Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Video recording cancelled.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Failed to record video",
Toast.LENGTH_LONG).show();
}
}
if I delete /NewDirectory/, the video file will be saved in the root folder of the SD card, and I get a message from this method from my method onActivityResult.
But when adding, /NewDirectory/I get the video saved in:content:://media/external/video/media/15625
mediaFile.mkdirs(); does not create a directory.
Where am I wrong?