Want to switch light on/off and not succeeding. Probably not getting the most from th documentation. In any event, this is what I have tried.
Amongst the imports I have
import android.hardware.Camera;
Within the body
Camera myCamera;
.......
myCamera = Camera.open();
.......
Camera.Parameters myCameraParameters = myCamera.getParameters();
myCameraParameters.setFlashMode(FLASH_MODE_TORCH);
The above line brings up an error 'FLASH_MODE_TORCH cannot be resolved to a variable' I am assuming that I am missing an import which defines FLASH_MODE_TORCH.
Anyine point me in the right direction?
IF I am missing an import, where should I go in the documentation to find out what imports are needed for what statements, constants .....
Regards,
Oliver
I believe it should be Camera.Parameters.FLASH_MODE_TORCH. I was having some difficulty getting visibility to this parameter, but you should take a look at this questions They seem to have it figured out with an example.
This code might help comeone else
Camera.Parameters myCameraParameters = myCamera.getParameters();
String stringFlashMode;
stringFlashMode = myCameraParameters.getFlashMode();
if (stringFlashMode.equals("torch"))
myCameraParameters.setFlashMode("on"); // Light is set off, flash is set to normal 'on' mode
else
myCameraParameters.setFlashMode("torch"); // This turns the light on
myCamera.setParameters(myCameraParameters);
Regards,
Oliver
Related
I follow the following link's sample code
http://android.dronekit.io/first_app.html
and when I set API VehicleApi.getApi(this.drone).arm(true);
vehicleState.isFlying() automatically becomes true.
Can anybody tell me what this problem is?
What I need is:
1. take off, land
I read from some website that the dronekit-android does not support the mode changing. If so, how should I send the mavlink message to take off and land?
So far, I can sucessfully send the mavlink message to the PX4 board.
Thanks for replying.
Thank you for replying.
BR
SeanH
If you trace though some of the code in dronekit-android, you can see that isFlying is set here with the code below.
boolean isFlying = systemStatus == MAV_STATE.MAV_STATE_ACTIVE || ...;
MAV_STATE_ACTIVE, defined here states
System is active and might be already airborne. Motors are engaged.
So isFlying doesn't mean it's airborne but just that the motors are turned on. That occurs when you call VehicleApi.getApi(this.drone).arm(true); because you are literally arming the vehicle at that point.
For takeoff, you want to use the ControlApi. ControlApi.getApi(drone).takeOff(desired_altitude, listener) and for land you need to use VehicleApi.getApi(drone).setVehicleMode(VehicleMode.COPTER_LAND, listener)
The sample code you're looking at is very old. I suggest you follow the sample app from github.
I have not tried android-dronekit before and I noticed that the src folder have not been updated for more than two years on github.
I advice you to use python-dronekit because there is a powerful library called pymavlink in python and used in python-dronekit. You can build hyper application if you want but first try to takeoff and land in python.
Android Studio 0.4.6
Hello,
I am trying to use the camera and I have set the permissions like this:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-feature android:name="android.hardware.camera"/>
I have imported the correct package:
import android.hardware.Camera;
And I try and open the camera like this:
Camera camera = Camera. there is no open method;
All I get are the following:
Parameters
Class
Size
I have follow the developer documentation, I can't see I have done anything wrong.
many thanks for any suggestions,
Just try to paste camera = Camera.open(); or type it in manually. Sometimes the "clever" thing glitches.
By the way, did the tool suggest to import android.hardware.Camera; or you typed it manually? I mean, is it an Android project? (Typically you start with the automatically generated hello world example and then add extra functionality to it, if you did something else, it's easier to re-do it from the very beginning.)
For anyone in the future facing the same issue
import android.hardware.*;
I saw online this code used a lot:
public void onAccelerometerChanged(final AccelerometerData myAccelerometerData) {)
When I try to use it, eclipse will not recognize the AccelerometerData class.
I'm having a hard time:
Detecting tilt.
Using it to change the worlds physics with box2d.
It would help me if anyone could show me ways of detecting tilting and using it.
Thank you.
You can see this code used in the PhysicsExample where it is used to change the center of gravity.
You must use the same code branch as the one in the example you have found. Notice that I linked GLES2-AnchorCenter branch version of the PhysicsExample. This branch is the newest. There is no AccelerometerData class. It has been renamed to AccelerationData.
Tilting (phone orientation) can be detected in a similar fashion. You have to call the following methods in your Activity and pass the correct listener.
protected boolean enableOrientationSensor(final IOrientationListener pOrientationListener) {
return this.mEngine.enableOrientationSensor(this, pOrientationListener);
}
protected boolean enableOrientationSensor(final IOrientationListener pOrientationListener, final OrientationSensorOptions pLocationSensorOptions) {
return this.mEngine.enableOrientationSensor(this, pOrientationListener, pLocationSensorOptions);
}
I want to use zxing in an android project. I have download the code and the example app is running now (ZXingTestActivity). For your information, i am not very familiar with coding native android.
I want to use zxing to scan qr-codes to configurate an application. To avoid confusion between normal qrcodes and configuration qrcodes i want to print inverted/negative qrcodes on screen or paper.
To be able to scan these inverted/negative qrcodes, the camera must be in negative mode. How can i do this? I am not sure where to start, however....
In the ZXingTestActivity.java there is a clicklistener that specify some extra parameters to the IntentIntegrator, for example:
private final Button.OnClickListener scanProduct = new Button.OnClickListener() {
#Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
integrator.addExtra("SCAN_WIDTH", 800);
integrator.addExtra("SCAN_HEIGHT", 200);
integrator.addExtra("RESULT_DISPLAY_DURATION_MS", 3000L);
integrator.addExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);
}
};
Is it possible to add camera settings with addExtra and how do i format this? Is it possible? Or is there another way to configurate the camera to inverted/negative mode?
I do not know if it completely impossible with ZXing but with ZBar it is possible!
First download the ZBar android version on sourceforge:
http://sourceforge.net/projects/zbar/files/AndroidSDK/
Add project to eclipse
Open CameraPreview.java
Add a private var to the class:
private Camera.Parameters mCameraParams;
Add the following lines after the line: mCamera = camera; in the constructor CameraPreview:
mCameraParams = camera.getParameters();
mCameraParams.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
mCamera.setParameters(mCameraParams);
That's it! (run the project)
Also think that ZBar is faster to detect damaged barcodes. Is the same as the PC-version i have used in another project and does the job very well. Blink with your eyes and the code is there. No fancy things at all, just good!
#Erwinus, here's the code. I hope it's now clear why it is something you have already been completely given in previous comments. More homework and fewer accusations makes SO a happy place.
mCameraParams = camera.getParameters();
if (mCameraParams.getSupportedColorEffects().contains(Camera.Parameters.EFFECT_NEGATIVE) {
mCameraParams.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
}
mCamera.setParameters(mCameraParams);
Sorry there's not a way to do this via Intent. A clean patch adding this as an option would be attractive to commit. The only gotcha is that the camera must support the "negative" mode. Then it's trivial (you can see this behavior as a selectable option in Barcode Scanner+). Otherwise you have to flip the image yourself. Not hard, but takes a bit of code and CPU cycles.
I must be the first to face this problem because I can't find even a single thread about it.
Today I wanted to start on the camera aspect of my application needs.
I read up some documentation
my manifest looks like this:
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
I wrote this in the manifest ABOVE <application> and underneath <manifest>
What im doing is; I have created a new class.
using eclipse as my IDE.
I then declare a field:
Camera _camera;
In the constructor(just to test)
I tried to do:
_camera = Camera.open();
I got an error.
I use my real phone to test the app, because I have no webcam or anytihng for the simulator to use. And the simulator gives me a memory error when I tell it to have a camera.
Anyway, upon finding out why I can't use Camera.open (I included the package: android.graphics.Camera;) Because that is what eclipse included for me when i used to organize imports function.
I looked into the android.jar that eclipse attached for me. Contained in a folder thingy called Android 2.2 -> android.jar
I searched for android.graphics and took a peek in the content of Camera.class
It turns out that my Camera class only has these methods:
Camera()
applyToCanvas()
dotWithNormal()
finalize()
getMatrix()
restore()
rotateX()
rotateY()
rotateZ()
save()
translate()
I intentionally let the parameters out because they are of no importance.
To get to the actual question: Why?
Why is there no open() method, no release() method? and whatever else im missing.. '
Thanks for reading.
Todays lesson: Don't be a smart **s. I was indeed 950% sure I included that specific package. But it was the wrong package. derp. Thanks fo notifying me. Issue is solved.
You are using the wrong Camera.
android.graphics.Camera - A camera instance can be used to compute 3D transformations and generate a matrix that can be applied, for instance, on a Canvas.
android.hardware.Camera - The Camera class is used to set image capture settings, start/stop preview, snap pictures, and retrieve frames for encoding for video. This class is a client for the Camera service, which manages the actual camera hardware.
You are using a wrong Camera class. Use this one http://developer.android.com/reference/android/hardware/Camera.html
You are using Camera from android.graphics.Camera I suppose you need the one from android.hardware.Camera
(yes im 950% sure I have included the package:
android.graphics.Camera;)
You are looking for android.hardware.Camera.