Blog Infos
Author
Published
Topics
,
Author
Published

Today, I will share my recent experience of not reading the documentation 📖carefully about the <query> tag, which is introduced in Android11.

It leads to the broken camera 📷 functionality 😢

adb shell dumpsys package queries

ADB command to see the default visible packages

 

  • In the output, section look for forceQueryable section. It shows the list of packages that are visible automatically.

 

Output screenshot

 

🤯 Automatically visible packages depend on the device 📱 that runs the app

  • So, I have the following code to launch the camera 📷 intent
private fun launchCameraIntent() {
val takePhotoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
// Ensure that there's a camera activity to handle the intent
// Android11 or higher needs the <query> tag to be added in the Android Manifest file.
// It depend on the device, if by-default camera package is visible or not
takePhotoIntent.resolveActivity(packageManager)?.also {
// Create the File where the photo should go
val photoFile: File? = try {
createImageFile()
} catch (ex: IOException) {
// Something went wrong
null
}
// launch camera intent only if the File was successfully created
photoFile?.let {
val photoURI: Uri = // get photo file URI
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
startActivityForResult(takePhotoIntent, REQUEST_IMAGE_CAPTURE)
}
}
}
view raw CameraIntent.kt hosted with ❤ by GitHub

Camera intent code

 

  • As we discussed earlier default package visibility depends on the device, so I didn’t add the <query> tag in the AndroidManifest.xml file.
  • It works fine on Samsung S21 ultra(Android12). I didn’t test it on different devices e.g Pixel 3A, Pixel 5.
  • I release the app to the QA’s they tested it on the various devices (Samsung, Pixel, etc.), and found that camera 📸 functionality is not working on some devices that are running Android11 or higher 💔 🤯.
  • After investigation, I went through the documentation about Taking photos and package visibility and found that I missed the following line 🙊:

Automatically visible packages depend on the device.

Job Offers

Job Offers


    Engineering Manager – Apps Lifecycle

    Zalando SE
    Berlin
    • Full Time
    apply now

    (Senior) Android Software Developer (w/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

    Android Developer

    ClearScore
    London (Hybrid role)
    • Full Time
    apply now
Load more listings

OUR VIDEO RECOMMENDATION

,

Upgrade Android Studio experience by building your own plugins

Android Studio allows anybody to build and integrate plugins in the IDE to customize/enhance the development experience. This talk will introduce the different options for plugin development weighing in the pros and cons, and the…
Watch Video

Upgrade Android Studio experience by building your own plugins

Santosh Astagi
Software Engineer
Meta Platforms

Upgrade Android Studio experience by building your own plugins

Santosh Astagi
Software Engineer
Meta Platforms

Upgrade Android Studio experience by building your own plugins

Santosh Astagi
Software Engineer
Meta Platforms

Jobs

Fix

I have added the <query> tag in the AndroidManifest.xml file with the entry for intent with action android.media.action.IMAGE_CAPTURE

It fixes the issue 💃💃💃💃

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

CameraIntentQueryTagEntry

 

I see the following lint warning in Android Studio Dolphin🐬 but somehow it doesn’t show up in the Android Studio Chipmunk 🐿 😢

Lint warning to add <query> tag

😊😊 👏👏👏👏 HAPPY CODING 👏👏👏👏 😊😊

 

This article was originally published on proandroiddev.com on June 29, 2022

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Compose is part of the Jetpack Library released by Android last spring. Create Android…
READ MORE
blog
READ MORE
blog
Once, I thought what if Android Studio had a feature to quickly create any…
READ MORE
blog
A while back I wrote an article about how to set up wireless ADB…
READ MORE

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.

Menu