Documentation - https://developer.android.com/training/camera/photobasics
I have followed all the required steps to capture image using camera.
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // its always null
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
takePictureIntent.resolveActivity(getPackageManager())
- this line always returns null. and if i skip this check than camera opens but app crashes.
Open Image Capture. In the sidebar, click on your Android device. Choose the folder where you want to save your pictures using the drop-down menu. Then, select the images you want to transfer and click Download.
The Android Camera application encodes the photo in the return Intent delivered to onActivityResult() as a small Bitmap in the extras, under the key "data" . The following code retrieves this image and displays it in an ImageView . Note: This thumbnail image from "data" might be good for an icon, but not a lot more.
Jaakko's answer is correct, and here is a quick explanation:
Since API level 30, there have been changes in the package visibility. https://developer.android.com/about/versions/11/privacy/package-visibility
For your package manager to work properly, you need to declare <queries>
in your AndroidManifest.xml
:
Code:
<manifest package="your.package.name">
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
</manifest>
This works only for the default camera apps. If your app is using some 3rd party camera, you can find some info here: https://commonsware.com/blog/2020/08/16/action-image-capture-android-r.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With