Android Camera Intent only shows stock camera instead of all camera apps - android

I am integrating taking photo into my app using existing installed camera apps. On my phone, there are some camera apps installed, but I can only see the one that shipped with the phone.
Here is my code:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
File tempFile = // ....
Uri photoURI = FileProvider.getUriForFile(getActivity(), "my_fileprovider", tempFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, RC_CAMERA_RETURN);
}
What I expected:
The app will show a list of installed camera apps and the user can pick up one.
My phone info: Sony Xperia Z2 with the following installed camera apps
Camera from Sony ( shipped with Z2) ----- Only see this one
Camera ZOOM FX
Retrica

I'm afraid that the target app you are referring to did not register itself appropriately as camera app.
If you know exactly what app you want to open, you might specify that information in an explicit Intent to open that particular app. Otherwise the user has to pick one of the available apps.

you can use to get app's manifest and get the Intent action and you can directly add action to the intent,
check App to check manifest of any app installed in android link here
That's How I solved same problem.

Related

Taking and picking photos on Poco X3 with Android 11 does not work

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?

Get app that implicit Intent opens

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;

Android Intent ACTION_IMAGE_CAPTURE

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).

No Activity found to handle MediaStore.ACTION_IMAGE_CAPTURE Intent

I am using this quite simple piece of code to capture an image on an Android device.
File tmpFile = ...;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tmpFile));
startActivityForResult(intent, CAPTURE_IMAGE);
This works fine for thousands of users except for one running this on a Kindle device without camera. Today I got a crash report from a device with camera:
ANDROID_VERSION=4.2.1
BRAND=Hisense
PHONE_MODEL=M470BSA
STACK_TRACE=android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
at android.app.Activity.startActivityForResult(Activity.java:3370)
at android.app.Activity.startActivityForResult(Activity.java:3331)
...
I have put some exception handling around the code to catch the exception and show an error, but I have no idea why this piece of code is failing on this device. The user confirmed that the camera is working fine.
First, there is no requirement that a device have an activity that supports ACTION_IMAGE_CAPTURE, even if the device has an actual camera.
Second, particularly on Android 4.3+ tablets, the person using the device may not have access to an ACTION_IMAGE_CAPTURE activity, even if one is installed, as the person may be running in a restricted profile.

Launching a pdf asset from android menu?

I have included a file called "Manual.pdf" in my assets folder. I have created a menu button called "Help". I want the user to be able to go to the menu, press on the Help button, and launch the Manual.pdf file in whatever viewer the phone has installed.
I have read for a few hours on this site and other sites, but I just can't get the file to launch.
Thanks for any help.
There is no unified PDF reader for Android Devices. I assume that in the course of your research you would have found that, you could use an implicit intent to invoke a pdf reader if it does exists.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
intent.setType("application/pdf");
It works in some devices and fails in some other devices. ( so please check availability of intent using the package manager). If you are targeting a particular device then you could get the corresponding Activity Object and use an Implicit Intent.(com.htc.pdfreader for HTC Phones).

Categories

Resources