I am using camera intent for capturing selfie but by default it open back camera and I want front camera by default.
ContentValues values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, 101);
Add the following line:
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1)
Although, it doesn't seem to always work. But it's the best you can get using just intents.
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 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.
I am working on Android application in which I am taking picture from camera. I just want to set my camera orientation to be portrait. My code is given below from where I am sending request to OnActivityResult:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues(3);
values.put(MediaStore.Images.Media.DISPLAY_NAME, "testing");
values.put(MediaStore.Images.Media.DESCRIPTION, "this is description");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
imageFilePath = UserInfoActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
startActivityForResult(intent, 0);
Add these lines in your code
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startActivityForResult(intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
Add these lines in your Manifest.XML
<activity
android:name="ActivityName"
android:screenOrientation="portrait"
android:configChanges="orientation" >
</activity>
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
I am launching the image capture intent to take a picture, adding a uri so the picture is tiny. My problem is I want to set the output jpeg-quality before I start the activity.
ContentValues vals = new ContentValues();
vals.put(Media.DISPLAY_NAME, "test title");
vals.put(Media.MIME_TYPE, "image/jpeg");
Uri imageFileUri = context.getContentResolver()
.insert(Media.EXTERNAL_CONTENT_URI, vals);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
context.startActivityForResult(i, CameraImportActivity.CAMERA_REQUEST);
I suppose I could downsample after the picture is taken, but if I can request the activity do it for me I would like to do so.
As bonus questions, how do I change the album they get saved to in the gallery, and how do I prevent the camera activity from saving a copy in the default location (on my phone it is "photos")