I am trying to record a video from within my application using the following code
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE)
startActivityForResult(intent, CAPTURE_VIDEO_REQUEST_CODE);
This opens the Video Recording mode. I record the video and then tap to accept the recording. However, the recorded video is never saved to the SD Card. I have written my code to write to the SD Card as follows.
/** Create a File for saving an image or video */
private static File getOutputMediaFile(int type){
// Check that the SDCard is mounted
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "/Videos/MyCameraVideo");
// Create the storage directory(MyCameraVideo) if it does not exist
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
output.setText("Failed to create directory MyCameraVideo.");
Toast.makeText(ActivityContext, "Failed to create directory MyCameraVideo.",
Toast.LENGTH_LONG).show();
Log.d("App", "Failed to create directory MyCameraVideo.");
return null;
}
}
// Create a media file name
// For unique file name appending current timeStamp with file name
java.util.Date date= new java.util.Date();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(date.getTime());
File mediaFile;
if(type == MEDIA_TYPE_VIDEO) {
// For unique video file name appending current timeStamp with file name
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"VID_"+ timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// After camera screen this code will excuted
if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
//data is null over here
status.setText("Video File : " +data.getData());
Toast.makeText(this, "Video recorded successfully!", Toast.LENGTH_LONG).show();
}
}
}
Also, On debug, my data for the onActivityResult
method is null.
Can please someone tell me how to write the video to the SD card. My above code works fine when tested on an Android phone but does not do the same in Glass. Is it a bug?