I am currently working on a barcode scanning app, which uses the mobile vision api for the majority of processes. I am trying to implement a flash button so that a user may scan in low light, but for some reason the activation of flash freezes the camera feed. Is there some way to start flash with a button while the feed is active? To activate flash without interfering with other threads? Thanks!
i used this code in my custom camera Application.when User clicks the FlashOn Button then Flash will be start.i think this code will help to you.
try this code (OnButton Click) :
private void btnFlashOnClick() {
if (mCamera != null) {
// First get the Camera Parameters.
Camera.Parameters parameters = mCamera.getParameters();
// set FlashMode to camera parameters.
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
// set Parameters Objects to Camera.
mCamera.setParameters(parameters);
// Finally, Start the Preview Of a Camera
mCamera.startPreview(); // this Line is Usefull for MyApp.If you don't need then Remove this Line.
}
}
this code is works fine in my App..Hope this will helps you...(:
It really depends what camera api you are using as there are few.
CameraManager has
void setTorchMode (String cameraId, boolean enabled)
that lets you operate flash regardless of current state of the camera (and without a need to restart one), but it could be overridden by other apps too
Related
I use this code below to toggle on and off camera flash light
private void toggleFlash() {
try {
if(!flashOn) {
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
} else {
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
}
captureSession.setRepeatingRequest(captureRequestBuilder.build(), null, handler);
flashOn = !flashOn;
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
It works, but the issue is this. At first when I open the camera (without flash light), I can see the image preview from the camera clear, but when I toggle on the flash and toggle it off, the preview becomes more darker than the initial time of opening the camera.
I'm still new to the camera API but I guess the issue is coming from here
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
But I don't know the proper code to use to make the camera not to be dark. Anyone with a solution?
It's going black because you're turning off auto-exposure, and I suspect the default manual exposure and sensitivity values are so low that the image is very underexposed.
You don't need to turn auto-exposure OFF when you turn off the flash. To control the flash manually, you do need to make sure AE is not set to ON_AUTO_FLASH, ON_ALWAYS_FLASH, or ON_AUTO_FLASH_REDEYE, but that just means you can leave it as ON all the time, if you don't need automatic flash firing.
So just remove the bit about setting CONTROL_AE_MODE to CONTROL_AE_MODE_OFF
Torch and flash are two different setting in camera2.
You can try and control flash with these setting.
On
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
Off
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
I used video capturing code using built-in camera in an application, but it reporting issues some of android phones like OnePlus phones. in other phones it works perfectly, can anyone help me to solve this issue, i tried many times but it didn't work, I'm sharing my code below..
Acutually it is shows only in device like one plus, I try to use built-in cam for to recording video, in my project, After we click button for to record video, it will redirected to the built-in cam in the device, in other devices it's working perfectly. but in one plus version11 , after we click the button for to record video it will not redirected to built-in cam, it is just stuck with the same page.. this is the issue
private void captureVideo() {
Intent VideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (VideoIntent.resolveActivity(getPackageManager()) != null) {
VideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
VideoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
VideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 3);
VideoIntent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION,true);
startActivityForResult(VideoIntent, VIDEO_REQUEST);
}
}
Why isOperational() in mobile vision text recognizer returns false?
At first, mobile vision only show preview camera and after many tries to get the result, I saw that the texts recognized but in one device it works and in other device does not.
What should I do?
For example, in one device, isOperational() returns false, and it goes to readstate() and after that goes to looper() and stays on it!
in other device it only return false and doesn't go to looper.
I want ask other questions about it:
My first question is: how does isOperational() work? I can't understand it.
Maybe it goes to looper to download the native library in a queue and after many try, at last download completes and work. Can it be correct? Or is it just a bug that it goes to looper? Anywhere, what should I do?
Can I work on this when it works in one device I tried and in other does not? Or it must work in every device to I can work on it? And I get .apk from project but it can't install in devices, why?
Should it check for network?
Should it check for access to the memory?
note: it works with camera API and its deprecated. maybe the problem is with this!
TextRecognizer textRecognizer = new TextRecognizer.Builder(context).build();
textRecognizer.setProcessor(new OcrDetectorProcessor(graphicOverlay));
if (!textRecognizer.**isOperational**()) {
// Note: The first time that an app using a Vision API is installed on a
// device, GMS will download a native libraries to the device in order to do detection.
// Usually this completes before the app is run for the first time. But if that
// download has not yet completed, then the above call will not detect any text,
// barcodes, or faces.
//
// isOperational() can be used to check if the required native libraries are currently
// available. The detectors will automatically become operational once the library
// downloads complete on device.
Log.w(TAG, "Detector dependencies are not yet available.");
// Check for low storage. If there is low storage, the native library will not be
// downloaded, so detection will not become operational.*
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
if (hasLowStorage) {
Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
Log.w(TAG, getString(R.string.low_storage_error));
}
}
*// Creates and starts the camera. Note that this uses a higher resolution in comparison
// to other detection examples to enable the text recognizer to detect small pieces of text.*
cameraSource =
new CameraSource.Builder(getApplicationContext(), textRecognizer)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1280, 1024)
.setRequestedFps(2.0f)
.setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null)
.setFocusMode(autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO : null)
.build();
}
It doesn't produce any error and show preview camera but doesn't recognize texts in some devices.
I want to change the device's background each specific interval (30 seconds for example) . I've been searching for days for a similar project or tutorial but I didn't find anything helpful . As I guess the app that I'm going to code will be a service since I want it to run in the background . I have the background images included in the drawable folder . So can any one help ?? and thanks in advance
There is a great application that does this and it's opensource. It's called Muzei - link created by Roman Nurik. Once a day, this application gets wallpapers from Internet and change your background. You can totally get this code and modify the frequency of the background change, and strip all the web calls and redirect to your internal images
You can also code a plugin for Muzei. You will only have a little part of the code to make it work. It will be a lot easier. But, in the other hand, you will have less control on the time between every wallpaper change.
For your code it will be a mix between :
AlarmManager run every hour
// We want the alarm to go off 30 seconds from now.
long firstTime = SystemClock.elapsedRealtime();
firstTime += remainingMilisecondsToTopHour;
long a=c.getTimeInMillis();
// Schedule the alarm!
AlarmManager am = (AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME,
c.getTimeInMillis(), 1*60*60*1000, sender);
and Changing Wallpaper. Do not forget to add the permission of changing background in your manifest
// to set a background we need to use bitmap
InputStream is = getResources().openRawResource(R.Drawable.myImage);
// we set the phone background to that image.
Bitmap bm = BitmapFactory.decodeStream(is);
try {
getApplicationContext().setWallpaper(bm);
// add permission of background from manifest file
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Using a service in background all the time will use way more battery of your device.
Run one task every hour if you still want to use a service ;)
Finally you should register to the broadcast event Screen On/Off to avoid changing wallpaper while the device is idle and draining the battery for nothing
I'm using a Service that displays a view using WindowManager, and animation occurs every time I change the view's size using
windowManagerLayoutParams.height = newHeight;
((WindowManager) getSystemService(WINDOW_SERVICE)).updateViewLayout(mMainLayout, windowManagerLayoutParams);
If I disable manually the scale animations, no animation occurs.
Scale animation disabled manually like so:
http://www.cultofandroid.com/11143/android-4-0-tip-how-to-find-and-disable-animations-for-a-snappier-experience/
Is there a way to disable the window scale animations for my application programmatically?
I just had this same problem while working on a system overlay in the SystemUI package and decided to dig through the source to see if I could find a solution. WindowManager.LayoutParams has some hidden goodies that can solve this problem. The trick is to use the privateFlags member of WindowManager.LayoutParams like so:
windowManagerLayoutParams.privateFlags |= 0x00000040;
If you look at line 1019 of WindowManager.java you'll see that 0x00000040 is the value for PRIVATE_FLAG_NO_MOVE_ANIMATION. For me this did stop window animations from occurring on my view when I change the size via updateViewLayout()
I had the advantage of working on a system package so I am able to access privateFlags directly in my code but you are going to need to use reflection if you want to access this field.
As #clark stated this can be changed using reflection:
private void disableAnimations() {
try {
int currentFlags = (Integer) mLayoutParams.getClass().getField("privateFlags").get(mLayoutParams);
mLayoutParams.getClass().getField("privateFlags").set(mLayoutParams, currentFlags|0x00000040);
} catch (Exception e) {
//do nothing. Probably using other version of android
}
}
Did you try Activity#overridePendingTransition(0, 0)?
Check out the documentation:
Call immediately after one of the flavors of startActivity(Intent) or finish() to specify an explicit transition animation to perform next.