10

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.

towhid
  • 2,778
  • 5
  • 18
  • 28
  • The `resolveActivity()` returning null is answered here: https://stackoverflow.com/questions/62535856/intent-resolveactivity-returns-null-in-api-30. We'd need to see the stack trace for the crash, though, if it's not related to that. – Mike M. Sep 18 '20 at 06:51

2 Answers2

20

Jaakko's answer is correct, and here is a quick explanation:

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

Pavle37
  • 571
  • 9
  • 24
5

Add these to AndroidManifest.xml inside the manifest section:

<queries>
  <intent>
    <action android:name="android.media.action.IMAGE_CAPTURE" />
  </intent>
</queries>