I programmatically open the camera for video. I am telling the camera to put the video file in the specified location using the following code:
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); File out = new File("/sdcard/camera.mp4"); Uri uri = Uri.fromFile(out); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, GlobalUtility.CAMERA_VIDEO);
It works well on an HTC phone. But in my moto defy, it just ignores the MediaStore.EXTRA_OUTPUT parameter and puts the video in the default location. Therefore, I use this code in the onActivityResult () function to solve the problem:
private String getRealPathFromURI(Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(contentUri, proj, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } String realPath; try { File file = new File("/sdcard/camera.mp4"); if (!file.exists()) { Uri videoUri = data.getData(); realPath = getRealPathFromURI(videoUri); } } catch (Exception ex) { Uri videoUri = data.getData(); realPath = getRealPathFromURI(videoUri); }
Hope this helps some others.
source share