I found this Question but it doesn't work for me. (Nothing happens. Tested on Wiko Rainbow Jam)
Android - Camera2 : The easiest way to turn on the torch light
My App have to run on min. API Level 16! Is there an SupportCameraManager or an Library (under Apache), which can I use?
You Can Use this.
Initialize the NoobCameraManager singleton.
NoobCameraManager.getInstance().init(this);
You can optionally set the Log Level for debug logging. Logging uses LumberJack library. The default LogLevel is LogLevel.None
NoobCameraManager.getInstance().init(this, LogLevel.Verbose);
After that you just need to call the singleton to turn on or off the camera flash.
NoobCameraManager.getInstance().turnOnFlash();
NoobCameraManager.getInstance().turnOffFlash();
You can take care of the runtime permission to access Camera yourself or can allow the library to do it for you
NoobCameraManager.getInstance().takePermissions();
Note: The library will take permissions, if you haven't already, even without calling takePermissions() explicitly. This behavior may change in future.
It's easy to toggle Flash too
NoobCameraManager.getInstance().toggleFlash();
It's a good practice to release all the resources, once you're done.
NoobCameraManager.getInstance().release();
SOLUTION: The problem was that I only got the camera's parameters when turning on the light and turning off the light. This must apparently also be done in the constructor or in the overwriting onStart method.
#Override
protected void onStart() {
super.onStart();
camera = Camera.open(); //Also Call this
params = camera.getParameters(); //and this, in the Constructor
}
as fields:
private Camera camera;
Parameters params;
And then you can start the flashlight with these snippets of code: Android - Camera2 : The easiest way to turn on the torch light
Related
I am trying to create a custom FollowMe mission by sending a vehicle's GPS data on Android studio. i can send the vehicle coordinates,but the updateFollowingTarget gives a timeout error.I'm using mavic 2 zoom and dji sdk v1.14 .Did someone manage to fix this issue.
Thanks in advance.
It's a bug. It always returns timeout.
Just dont care about the error and it will work.
But it speed limited to like 15km/h so dont expect to much from it.
Edited (Do you know another function that i can use to follow a vehicle's GPS signal):
Yes, it involves more programming though.
You have to use virtualstick to control the drone. This is the only way to control the drone programmatically.
I have done it here, follows a tracker app running on a phone on my head:
https://www.youtube.com/watch?v=i3axYfIOHTY
Im working on a python api for dji. In that framework the top level code looks like below. The virtualstick calls are inside move_towards():
while True:
tracker_location = api.tracker.get_location()
drone_target_location = copy.deepcopy(tracker_location).move_to(Changeable.radius.get_value(), Changeable.bearing.get_value())
drone_location = api.drone.get_location()
course_to_tracker = drone_location.get_course(tracker_location)
heading = api.drone.smooth_heading(course_to_tracker)
drone_target_distance, drone_speed, course = api.drone.move_towards(drone_target_location, height=current_altitude, heading=heading, lowest_altitude=Changeable.lowest_altitude.get_value(), deadzone=[Changeable.dead_zone0.get_value(), Changeable.dead_zone1.get_value()], k_distance=[float(Changeable.k_dist0.get_value()), float(Changeable.k_dist1.get_value())], speed_deadzone=Changeable.speed_deadzone.get_value())
I'm issuing a simple command to my mediaControllerCompat:
controller.adjustVolume(-1, 0);
Yet my app FCs with...
java.lang.IllegalArgumentException: Bad direction 3
at android.os.Parcel.readException(Parcel.java:1469)
at android.os.Parcel.readException(Parcel.java:1419)
at android.media.IAudioService$Stub$Proxy.adjustStreamVolume(IAudioService.java:1097)
at android.media.AudioManager.adjustStreamVolume(AudioManager.java:952)
at android.support.v4.media.session.MediaSessionCompat$MediaSessionImplBase.adjustVolume(MediaSessionCompat.java:1376)
at android.support.v4.media.session.MediaSessionCompat$MediaSessionImplBase.access$1700(MediaSessionCompat.java:963)
at android.support.v4.media.session.MediaSessionCompat$MediaSessionImplBase$MediaSessionStub.adjustVolume(MediaSessionCompat.java:1602)
at android.support.v4.media.session.MediaControllerCompat$MediaControllerImplBase.adjustVolume(MediaControllerCompat.java:969)
at android.support.v4.media.session.MediaControllerCompat.adjustVolume(MediaControllerCompat.java:252)
at pl.qus.xenoamp.NewMainActivity.onKeyDown(NewMainActivity.java:1149)
MainActivity being the caller of mentioned line... What is WRONG?!
This was an internal bug in the Android Support Library has been fixed as of version 23.1.0.
Previous Answer
This is a bug in the support library that affects pre-API 21 devices that use local playback (i.e., have not called setPlaybackToRemote()) - the order of parameters sent to AudioManager.adjustStreamVolume() as per the source code is incorrect - hence why the direction appearing as 3 - the value for STREAM_MUSIC.
You may be able to temporarily work around it by always calling setPlaybackToRemote() on pre-API 21 devices, passing in a VolumeProviderCompat that does correctly call AudioManager.adjustStreamVolume(), but you must also handle the other methods of VolumeProviderCompat such as retrieving the max volume (via getStreamMaxVolume()) and current volume (via getStreamVolume()) as well as setting the volume (via setStreamVolume()).
I came across the same error using API 23 (not the Support Library) and running on an M device. I solved it by listening for the error and calling an API 1 method in its place, when necessary.
try {
...
} catch (IllegalArgumentException e) {
audioManager.setStreamVolume(STREAM, VOLUME, FLAGS);
}
Since the Compat interface calls the internal methods for system volume control, you could also instantiate an instance AudioManager if you are not directly declaring one already.
I'm trying to build a QR Code reader following this tutorial
http://code.tutsplus.com/tutorials/android-sdk-create-a-barcode-reader--mobile-17162
I managed to get everything working, except that I need the camera to be the front camera of my device instead of the rear camera. I can't find any place in the tutorial that allows me to change this. I tried following this answer, but I still could not get it to work.
Mainly, my issue is with importing the library. I get the following error.
operator is not allowed for source level below 1.7
When I set my compiler settings to 1.7, I get this
Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead
I'm not exactly very proficient with Android and I apologize if it might not be a good question.
So, any way for me to use ZXing with the front camera in my app? Any links?
Thank you very much.
The source code uses Java 7. Android does not require Java <= 6. You can see that the build provided in the project happily feeds Java 7 bytecode to dex and produces a working app. I am not sure what tool you are using that suggests otherwise. Maybe it is old.
You should not need to copy and compile the project's code though. Why is that necessary? use the core.jar file.
You don't need any of this to use the front camera. Just invoke by Intent (https://github.com/zxing/zxing/wiki/Scanning-Via-Intent) and set extra SCAN_CAMERA_ID to the ID of the camera you want -- usually 1 for the front one.
Example:
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
intent.putExtra("SCAN_CAMERA_ID", 1);
If you use IntentIntegrator, you can use setCameraId() to specify the front camera:
IntentIntegrator integrator = new IntentIntegrator(yourActivity);
integrator.setCameraId(1);
integrator.initiateScan();
After quite a few search i found how to use the front camera. There is this piece of code in com.google.zxing.client.android.camera.CameraConfigurationManager.java
public void openDriver(SurfaceHolder holder) throws IOException {
Camera theCamera = camera;
if (theCamera == null) {
theCamera = Camera.open();
if (theCamera == null) {
throw new IOException();
}
camera = theCamera;
}
theCamera.setPreviewDisplay(holder);
jus change the Camera.open() to Camera.open(1)
worked fine for me
Is it possible somehow to set Live Wallpaper programmatically using my Application?
I am working on an Application that her purpose is to choose some of the Installed Live Wallpapers on the device and to set it as a Live Wallpaper. This action need to be completed via my Application.
As I was researching I found some answers that this can be done with rooting the Android Device?
Can some one help me out how to do that exactly?
Android OS prior to Jelly Bean does not allow you to programatically set a live wallpaper.
For now Jelly Bean supports changing the Live Wallpaper programtically without user interaction
Sorry to break it to the nay sayers but it is possible to set a live wallpaper programmatically WITHOUT user interaction. It requires:
Your app to be system-privileged
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
Java reflection (super hacking code)
A class reference to the desired WallpaperService (live Wallpaper)
NOTE: For item #3, I used my own live wallpaper, MyWallpaperService class
This can only be done if your app is system-privileged and has this permission in the manifest:
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
Now, using reflection, you can call the hidden methods of WallpaperManager to manually set the live wallpaper:
WallpaperManager manager = WallpaperManager.getInstance(context);
Method method = WallpaperManager.class.getMethod("getIWallpaperManager", null);
Object objIWallpaperManager = method.invoke(manager, null);
Class[] param = new Class[1];
param[0] = ComponentName.class;
method = objIWallpaperManager.getClass().getMethod("setWallpaperComponent", param);
//get the intent of the desired wallpaper service. Note: I created my own
//custom wallpaper service. You'll need a class reference and package
//of the desired live wallpaper
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
intent.setClassName(context.getPackageName(), MyWallpaperService.class.getName());
//set the live wallpaper (throws security exception if you're not system-privileged app)
method.invoke(objIWallpaperManager, intent.getComponent());
Refer to the source code:
LiveWallpaperActivity
LiveWallpaperPreview
Recently I went thru the code for accessing the camera using flash ActionScript3 and I have tested the code in iMac machine, iPhone and Android.Now based on this, I am developing an application for Android which includes the accessibility of the front camera. Now my Problem is I dont know how to access the front camera? We should use some other code or should we specify which camera should be accessed? First of all, can we access the front camera thru flash?
I made a simple android app. Here is the code for selecting camera window
public class SelectCameraAlertAndroid extends StartAlertAndroid_design{
public function SelectCameraAlertAndroid() {
frontCameraButton.addEventListener(MouseEvent.CLICK, onFrontCamera);
backCameraButton.addEventListener(MouseEvent.CLICK, onBackCamera);
}
private function onFrontCamera(event:MouseEvent):void {
Model.model.camera = Camera.getCamera("1");
Model.model.cameraSelectedSignal.dispatch();
dispatchEvent(new Event("closeMe"));
}
private function onBackCamera(event:MouseEvent):void {
Model.model.camera = Camera.getCamera("0");
Model.model.cameraSelectedSignal.dispatch();
dispatchEvent(new Event("closeMe"));
}
}
Not true. You can access the front camera on Android.
The only problem is that you don't get to use the CameraUI(pretty sure).
var camera = Camera.getCamera("1");
camera.setMode(stage.stageWidth, stage.stageHeight, 30, true);
var video:Video = new Video(stage.stageWidth, stage.stageHeight);
video.attachCamera(camera);
addChild(video);
Note: This answer is outdated. Please refer to the other answers for updated information.
Currently, AIR only supports access to the primary camera on an Android device.
http://forums.adobe.com/thread/849983
Official documentation: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
"On Android devices, you can only access the rear-facing camera."