Motorola Android 2.2 camera ignores EXTRA_OUTPUT

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.

+4
source share
2 answers

Just because /sdcard/ is the sdcard directory on one phone, and one Android assembly does not mean that it will remain unchanged.

You want to use Environment.getExternalStorageDirectory() , as Frankenstein's comment suggests. It will always work to get the SD card directory.

You will also want to verify that the SD card is currently mounted, as the phone may be in USB storage mode.

Try something like ...

 if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ Log.d(TAG, "No SDCARD"); } else { File out = new File(Environment.getExternalStorageDirectory()+File.separator+"camera.mp4"); } 
0
source

I made this way and still have not found any error. So please try this with moto defy so that I can find out the reality.

Assign a call:

 Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE); startActivityForResult(intent,2323); 

In action on the result:

 Uri contentUri = data.getData(); 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(); String tmppath = cursor.getString(column_index); videoView.setVideoPath(path); 
0
source

Source: https://habr.com/ru/post/1380328/


All Articles