Is any solution to put some parameter to Intent(MediaStore.ACTION_IMAGE_CAPTURE) that would take photo with flash as default parameter?
There is no Intent extra to allow you to control the flash mode for ACTION_IMAGE_CAPTURE. Even if there were, not all camera apps would honor it.
To check if the Android device has a flash available, you can do this simple check :
context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
This check will return true if there's a flash available on the device or false if it doesn't.
Read more about : FEATURE_CAMERA_FLASH
Also after doing quite a bit of digging on Camera intent, turns out the only extra parameter you could use is :
MediaStore.EXTRA_OUTPUT
Reference : Intent does not set the camera parameters
Related
I am working on the Camera API and am confused between the following two Intents:
ACTION_VIDEO_CAPTURE
> added in API level 3
String ACTION_VIDEO_CAPTURE
Standard Intent action that can be sent to have the camera application
capture a video and return it.
The caller may pass in an extra EXTRA_VIDEO_QUALITY to control the
video quality.
The caller may pass in an extra EXTRA_OUTPUT to control where the
video is written. If EXTRA_OUTPUT is not present the video will be
written to the standard location for videos, and the Uri of that
location will be returned in the data field of the Uri. As of
LOLLIPOP, this uri can also be supplied through setClipData(ClipData).
If using this approach, you still must supply the uri through the
EXTRA_OUTPUT field for compatibility with old applications. If you
don't set a ClipData, it will be copied there for you when calling
startActivity(Intent).
INTENT_ACTION_VIDEO_CAMERA
added in API level 3
String INTENT_ACTION_VIDEO_CAMERA
The name of the Intent action used to launch a camera in video mode.
Constant Value: "android.media.action.VIDEO_CAMERA"
If I want to capture a Video from a Camera App, I would of course launch the Camera in the Video mode but both Intents seems to do that. How are they different?
There are two major differences.
With ACTION_VIDEO_CAPTURE, you can specify a destination folder.
With ACTION_VIDEO_CAPTURE, your user can't change the camera mode other than the video camera mode.
And, also, if I recall correctly, your activity can receive the onActivityResult callback only with ACTION_VIDEO_CAPTURE.
I'm working with some legacy code and the camera is opened using
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Which is fine. However, some code is running when the camera app is open (I'm not sure entirely why), but it does something if the camera app is in front of the user. The "top" app is retrieved, and then the code that checks if the camera is on top is:
boolean isCameraOnTop = topName.toLowerCase().indexOf("camera") != -1;
This was working fine for some time but we've been testing with a new device whose default camera app name is NOT "camera", but something else ("org.codeaurora.snapcam" if you must know). This approach seems flimsy as any device can have any default camera app.
SO, my question is, when I launch the camera app via the ACTION_IMAGE_CAPTURE intent, how can I find the app that actually gets opened?
After some searching, I found the solution:
activity.getPackageManager().resolveActivity(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
I am using camera intent to take a picture in a Service by using following code
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
getApplication().startActivity(intent);
} catch (final ActivityNotFoundException e) {
e.printStackTrace();
} catch (final Exception e) {
e.printStackTrace();
}
It can take the picture; however, every time it shows the preview GUI (having captured picture, Save and Discard buttons). I want to ignore the step, just likes the default capture camera (capture and saving without preview). How could I modify the code? Thank all
Note that: I do not want to use camera2API to make a new app. I want to use the default camera app. Someone said that
"The camera app doesn't give other apps the option to disable the confirmation screen, even though the camera app itself doesn't show the confirmation screen.
Therefore it is not possible for not showing the confirmation screen."
It looks bad new in the past. I am using Android 5.0. Is it possible now?
I found a good solution using adb shell
adb shell "am start -a android.media.action.STILL_IMAGE_CAMERA" && sleep 1 && adb shell "input keyevent 27"
Notice the action is STILL_IMAGE_CAMERA
Reference Android 4.4 won't allow me to save a picture when captured using adb commands
It is impossible.
You cannot control the behavior of the default camera app. Worse than that, you do not know what app will be used to fulfill your ACTION_IMAGE_CAPTURE intent. The end user has full power to install an alternative camera app, or may have malware installed that pretends to be a camera app (being a camera app means in this context that the manifest declares that it can perform ACTION_IMAGE_CAPTURE). But first of all, the ODMs preinstall camera apps that not necessarily behave the same way as the AOSP camera.
Such app may follow the contract for ACTION_IMAGE_CAPTURE intent response, but there is no guarantee. SO is full of questions about situations where the preinstalled camera app does not recognize extras correctly, or produces unexpected results.
Even if the result looks correct, there is no way for your app to know if the picture is actually being taken by the camera. It could be an image from the gallery, or a fake image, if the camera app chooses so.
I'm trying to start default android wallpaper chooser. I'm using:
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(intent);
This code works but it opens app chooser. I want to open "Wallpapers" directly. My minSdkVersion is set to 16.
By "default" you seem to mean the wallpaper app that came with Android OS, rather than other wallpaper apps that the device may have. You can force Android to launch a particular activity by setting the component in the intent.
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
intent.setComponent(...);
startActivity(intent);
However, this is a risky thing to do. If you run this code on a device that doesn't have the wallpaper app that you've specified, then you will get an ActivityNotFoundException.
Do you really need to launch one particular wallpaper app? A central feature of Android is that you say what you want to do, and it finds the app to do it. I don't know what your goal is, but another function that might be helpful is PackageManager.resolveActivity. You can use it to discover, in code, what app would be launched for a particular intent.
http://developer.android.com/reference/android/content/pm/PackageManager.html
Hope this helps.
I have a simple Android app that tries to take a picture and send it to a server as HTTP POST with multipart data. The problem is that the the behavior of Androids Intent is different on some phones. When I run
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
on HTC One (Android 4.1.1) and Sony Xperia Z1 (Android 4.4.4), it stores the image in the gallery and calls like the one below works:
data.getData().getPath();
(data is an instance of Intent), whereas when I run the same code on LG Nexus 5 (Android 4.4.4), the image is not stored, and
data.getData();
returns null.
What I need is a way to store the image (temporally), so I can transfer it to the server.
Looks like there could be a bug in the recent android stock camera, please see this issue report on android. According to the bug, the data field returned by the camera intent could come back null in default behavior. (MediaStore.EXTRA_OUTPUT is not used).
To guarantee you always get image, allocate a file yourself and pass that uri in camera intent extras as MediaStore.EXTRA_OUTPUT
The best practice in allocating a temporary image file is to ensure the underlying media is mounted, see this sample code snippet on android developer site. On a successful completion of camera intent, just use the file uri you allocated...do not use getData (could be null).