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.
Related
I recently updated my Poco X3 NFC 64GB test device to Android 11:
MIUI Global 12.0.8(RJGEUXM)
Android 11 RKQ1.200826.002
Ever since I am unable to take or pick photos in my app. On other Android 11 devices (and emulator) everything works fine. The app is compiled to API level 30.
I start the photo picker chooser like this:
private void pickPhoto() {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(intent, 100);
}
}
This works fine, but after I have picked a photo it returns to the app, triggering onActivityResult with resultCode 0 (RESULT_CANCELED) and data is null too. On other Android 11 devices I can retrieve the photo from the data, but not on my Poco. Yes I did add the necessary query to the manifest file (else I wouldn't be able to open the picker in the first place).
When I try to fetch a photo from the camera I have exactly the same issue. Again on other Android 11 devices this works fine. So yes I did add and use the necessary file provider.
Sometimes a toast pops up about not having granted the right permissions. Do any of you guys have a Poco phone and like to try it out? I wonder if the Poco rom is just broken or something.
UPDATE
I've narrowed down the problem. It turns out that if startActivity() starts a camera/gallery activity directly it works fine. However if you're prompted a chooser first (e.g. because you have multiple gallery apps) it goes wrong.
So if you pick a gallery app and say to always use it in the future, the next time it will open that gallery app directly and then it works correctly.
If you use Intent.createChooser() it never works right. Even if it contains only one intent that is launched directly without prompting a chooser it fails to return a photo.
Can we agree that this is a MIUI bug?
I am using MediaStore.Audio.Media.RECORD_SOUND_ACTION to open sound recorder application, I am not able to open application as no default application present, then i install two voice recorder application even though not able to see these application in my chooser intent. I am using following code-
Intent soundRecorderIntent = new Intent(); // create intent
soundRecorderIntent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION); // set action
startActivityForResult(soundRecorderIntent, ACTIVITY_RECORD_SOUND); // start activity
It works well in marshmallow
The code is correct and you've probably found an app that supports the intent by now. But to prevent that others waste their time like I did, here's a quick note:
Most of the currently top rated voice recording apps in the Play Store do not provide the necessary intent filter.
That seemed so unrealistic to me that I doubted my code when it didn't work after having installed the five most popular voice recording apps. But there's a handy manifest viewer app that reveals that their manifests simply do not declare the intent filter. So, as said, the code is correct.
To save you the time from searching for a suitable app, here are two that are invocable:
Audio Recorder from Sony
Samsung Voice Recorder from Samsung
There is no requirement for a voice recorder app to support this Intent action, and apparently your device does not ship with an app that supports this Intent action either. Your code itself seems fine.
If recording is optional to your app, catch the ActivityNotFoundException and tell the user that they do not have a recorder, and perhaps suggest to them that they install one that you test that works, if you can find one.
Otherwise, record the audio yourself, using MediaRecorder.
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;
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
Platform: ASUS Nexus 7, running JellyBean
I've created a kiosk application by making it the default HOME / LAUNCHER intent. I need to be able to get out of it, to the stock android launcher, via a secret code for service and maintenance.
I've searched all over, and can't find a good, succinct answer. The best I've come up with is to create an intent chooser (Intent.createChooser(Intent i, String title)) and choose between my launcher and the stock launcher. This is okay, but really a workaround.
I've tried:
PackageManager pm = this.getPackageManager();
try {
Intent i = pm.getLaunchIntentForPackage("com.android.launcher");
if (i != null)
this.startActivity(i);
}
catch (ActivityNotFoundException e) { }
and I get null for the intent every time. Yet, the stock launcher shows a package of "com.android.launcher" on my tablet. Clearly I'm getting something totally wrong here.
Step #1: Document that they need to run your app manually once out of the launcher before setting it up as the home screen.
Step #2: On that first run, use resolveActivity() to find out what the default home screen is, and hold onto the relevant pieces of information from the ResovleInfo (e.g., the component name) in some persistent data store.
Step #3: Use that data to bring up the default home screen as needed from whatever back door you have in your kiosk app.