I tried other questions' methods, but for me, these methods do not work .
I want to use intent to start front camera. I try to do it
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("android.intent.extras.CAMERA_FACING",1);
mFile = Utils.getVisitorImage();
Uri imageUri = FileProvider.getUriForFile(
getActivity(),
getActivity().getPackageName() + ".fileprovider",
mFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAMERA_PHOTO_REQUEST_CODE);
but,it does't work. my device is Android 7.1.1 or some device higher 6.0.1.
How to use intent start front camera? I hope someone help me.Thanks.
Related
I'm using this code to open camera intent :
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePicture.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startActivityForResult(takePicture, 0);
And it works fine but only on Samsung devices (8\9) with android 8
after I take a picture the preview is all blurry ,
anyone got that weird behavior ?
( I also tried without the putExtra line )
Here are the screenshots :
]3
you have to give a photo path Uri as an extra in the camera intent as:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), mUserID + ".jpg");
Uri photoPath = getUriForFile(mContext, BuildConfig.APPLICATION_ID, file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath); //--> here
startActivityForResult(Intent.createChooser(intent, "Complete action using"), REQUEST_CODE_CAMERA);
then, you can get the captured image in that Uri itself in onActivityResult
I need to call Intent for image and video both at same time . It seems impossible similar to this . So a alternate way to do this is createChooser() . But i am kinda stuck with the code below .
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, file.getAbsolutePath());
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, file.getAbsolutePath());
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
Intent[] intentArray = new Intent[]{takePictureIntent};
chooserIntent.putExtra(Intent.EXTRA_INTENT, takeVideoIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose an action");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, 1);
MediaStore.EXTRA_OUTPUT not working . The file is empty after returning from camera . However it does open a chooser as below but file is empty .
Questions:-
1.How to can i combine both intents and provide separate files as MediaStore.EXTRA_OUTPUT?
2. As we all know there are hundreds of camera apps in android so is this a good way to open such intent(Will it work in all devices regardless of manufacturer and API Level) ? Or i should move with an AlertDialog to open intent for each action seperatly .
Try this below code :
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = Intent.createChooser(takePictureIntent, "Capture Image or Video");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takeVideoIntent});
startActivityForResult(chooserIntent, CAMERA_IMAGES_REQUEST);
I am working on application where I am recording video from Camera Intent. On my Samsung mobile MediaStore.EXTRA_VIDEO_QUALITY is working and even my allocated memory size also works but same application on my Google Pixel there MediaStore.EXTRA_VIDEO_QUALITY is not working and even allocated size of memory is not working with camera intent.
My code is given below:
public void takeVideoFromCamera(){
File mediaFile =new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/myvideo.mp4");
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Uri videoUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// videoUri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", mediaFile);
videoUri = FileProvider.getUriForFile(this, "i.am.ce.by.murgqcy.provider", mediaFile);
} else {
videoUri = Uri.fromFile(mediaFile);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 5491520L);//5*1048*1048=5MB
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,45);
startActivityForResult(intent, VIDEO_CAPTURE);
}
According to MediaStore.EXTRA_VIDEO_QUALITY
You should change the value of MediaStore.EXTRA_VIDEO_QUALITY from 0 to 1.
0 means low quality
Thus could be the solution intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
Is there an Intent for starting a camera with options to capture both Pictures and Videos on Android?
I've used both MediaStore.ACTION_VIDEO_CAPTURE and MediaStore.ACTION_IMAGE_CAPTURE to capture either audio or video, but I can't find an Intent that will get the option for switching between both of them, as in this example app:
Thanks!
It is not possible to capture both image and video using the same intent, Your options are
1) Create your own camera this repo can be a good start But it is going to be a too much effort.
2) Use the Chooser Intent and pass the intent for both image and video, this will give you the option to choose between application which record video and camera separately. In this you cannot do both the things at same time but can choose application according to what you want to do, capture an image or record a video. Below is the code that works for me.
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = Intent.createChooser(takePictureIntent, "Capture Image or Video");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takeVideoIntent});
startActivityForResult(chooserIntent, CAPTURE_MEDIA_RESULT_CODE);
I achieved it :)
You can do it by following --
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType("*/*");
intentArray = new Intent[]{takePictureIntent,takeVideoIntent};
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose an action");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, 1);
Similar example here
Happy coding :)
I could capture both image and video by using the below code.
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
I am using this code:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File("/sdcard/picture.png");
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photo));
Uri imageUri = Uri.fromFile(photo);
startActivity(intent);
I would like to use this intent with a pre-defined setting, like front facing by default every time I fire the camera. Is that possible?
This is the front Camera intent, use it in your code!
here is an good tutorial: http://www.vogella.com/articles/AndroidCamera/article.html
int CAMERA_FACING_FRONT
Read more here: http://developer.android.com/reference/android/hardware/Camera.html