How to Block Camera switching in android? - android

I want to use font camera by default and want to disable the switch option to the back camera.
How can i do it???
var i = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
i.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
i.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
startActivityForResult(i,101)
}```

You would need to use the camera APIs directly or using a library (CameraX, Fotoapparat, CameraKit/Android, etc.).
Your current code is launching the user's choice of camera app, and you have no means of forcing that camera app to disable certain cameras.
Also, please note that not every Android device has a front-facing camera. If that is a requirement of your app, put the appropriate <uses-feature> element in your manifest.

Related

removing intermediary screen with picture

I am using this method to open my camera and take a picture:
public static void openCamera(Fragment fragment, Uri fileUri) {
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePicture.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
takePicture.putExtra("return-data", true);
if(takePicture.resolveActivity(fragment.getContext().getPackageManager())!=null){
granUriPermission(fragment.getContext(), fileUri, takePicture);
fragment.startActivityForResult(takePicture, Constants.Intents.INTENT_IMAGE_CAMERA);
}else{
Toast.makeText(fragment.getContext(), R.string.error_no_camera_app, Toast.LENGTH_SHORT).show();
}
}
Right after I take the picture I get this screen where I am asked if I want to keep or delete the picture I just took:
What is this screen?
Can I force its orientation to be in the landscape mode?
Can I remove this extra step/screen and go straight to my fragment where I show the picture?
What is this screen?
It appears to be a confirmation screen.
Can I force its orientation to be in the landscape mode?
No, because that is not from your app. It is from one of hundreds of different camera apps that might be started via your ACTION_IMAGE_CAPTURE Intent.
Can I remove this extra step/screen and go straight to my fragment where I show the picture?
Probably not. You are welcome to contact the developers of that camera app and ask them, but their solution would be only for their app. It would not help you with the hundreds of other camera apps that you might encounter, across the ~10,000 Android device models and ~2 billion Android devices.
If you want complete control over the camera UX — at the cost of complexity — use a third-party camera library (e.g., CameraKit-Android, Fotoapparat) that wraps around the native camera APIs (e.g., android.hardware.Camera, android.hardware.camera2.*).

How to make the ZXing scan using the front camera not the back camera in Android?

I am using the ZXing by the following code ContinuousCaptureActivity, and the zxing using (by default) the back camera to scan, how to make it scan using the front camera ?
set extra SCAN_CAMERA_ID to the ID of the camera you want
usually 1 for the front one.
for example
intent.putExtra("SCAN_CAMERA_ID", 1);

Android auto focus when continuous auto focus modes are not supported

I have a camera in my app and I want to make it auto focus continuously in the same way that the phone's camera does it. I found the modes FOCUS_MODE_CONTINUOUS_VIDEO and FOCUS_MODE_CONTINUOUS_PICTURE, but they are not supported by some of the HTC Gingerbread phones I'm testing on.
This is what I'm doing to determine whether I can use these modes:
Camera.Parameters parameters = mCamera.getParameters();
List<String> supportedFocusModes = parameters.getSupportedFocusModes();
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
}
else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
// auto focus on request only
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
}
Running on several different Gingerbread HTC phones I don't get the continuous modes back, but I get "auto". This lets me auto focus on demand (when I call mCamera.autoFocus(null), but the camera will not refocus if the user moves the camera.
I cannot set the focus mode to anything the camera does not support, and if I do it shows up blank.
One solution that I tried is to call mCamera.autoFocus(null) on a timer. This causes the camera to refocus continuously, even if it is already in focus.
Is there a way to implement a continuous auto focus experience on these phones? When I look at HTCs camera app on these phones it does have continuous auto focus - as you move around the camera refocuses and does not keep refocusing once the picture is in focus.
We had a requirement to support a very wide range of phones. My solution in the end was to handle each case differently.
For the scenario of phones without continuous auto-focus support I implemented a utility to listen to the accelerometer using SensorManager and trigger mCamera.autoFocus(...) whenever the user moves the camera.
There were also some older tablets that only supported fixed focus (who would use such a thing!), in that case the picture needed to be taken immediately - not on the focus callback.
For most modern phones the code snippet above was fine to use FOCUS_MODE_CONTINUOUS_PICTURE.
I got a similar pb on my samsung S4 and I solved it with:
camera.setParameters(parameters);
camera.autoFocus(null);
This is suggest in the Google doc here.
To make the camera parameters take effect, your application has to call setParameters(Camera.Parameters).

Turn off auto focus in android

It is any way to turn off auto focus in camera in code my application. I want to check how my scanner work if phone has no auto focus, but in my phone I have that function.
Use FOCUS_MODE_INFINITY or FOCUS_MODE_FIXED. You can also use FOCUS_MODE_MACRO, but that will require holding your phone quite close to the object you're scanning.
On a second thought, the word 'scanner' evokes thoughts of barcodes and QR codes, so unless you print them as full-size page, you actually might be better off with FOCUS_MODE_MACRO.
You can set the desired focus mode with Camera.Parameters.setFocusMode() when opening your camera.
You Can use mCamera.cancelAutoFocus();
Also if you want to set Macro or another Focus Mode, you shall write:
Camera.Parameters mParam = mCamera.getParameters();
mParam.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
mCamera.setParameters(mParam);
All the focus mode and Camera parameters are availble here:

Android Front Facing Camera - empty (0km) file or start failed on some devices

I had this problem with my app (ScareApp) that uses the front facing camera to record video. I "think" I've finally resolved the issue, so thought I would post it here for any developers that run into the same thing....
Basically..
The android MediaRecorder allows you to define the Video and Audio Encoder, and according to the docs, DEFAULT can be used for each.
However, this refers to the main camera's settings, which is often a far higher spec than the front facing camera.
DEFAULT on the Droid Razr for example, selects an encoding (MPEG_4_SP) that isn't available for the Front facing camera, and this results in an empty (0kb) file being produced (or on some other devices a Camera 100 - start failed error).
My other option was to use the CameraProfile.get method to lookup what the HIGH_QUALITY settings, but again, this by default uses the main camera.
To get around this, you can set the ID of the front facing camera by using
CameraProfile.get(<CameraID>, CamcorderProfile.QUALITY_HIGH);
My current work around is as follows:
CamcorderProfile profile = CamcorderProfile.get(FrontFacingCameraId, CamcorderProfile.QUALITY_HIGH);
if(profile != null) {
_recorder.setAudioEncoder(profile.audioCodec);
_recorder.setVideoEncoder(profile.videoCodec);
}else {
//default to basic H263 and AMR_NB if profile not found
_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
}
Or alternatively, you can skip setting the Encoders, and just use
_recorder.setProfile(profile);
But as my app allows the user to select the resolution, I need to set the encoder's.
Hopefully this will help someone and save the time and hassle it has caused me!
Cheers,
Mark

Categories

Resources