Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

639
Vistas
Consider adding a queries declaration to your manifest when calling this method when using intent.resolveActivity in android 11

I've an extension function for opening an intent for my activities:

fun Activity.openIntent(action: String?, type: String?, uri: Uri?) {
    Intent()
        .apply {
            action?.let { this.action = it }
            uri?.let { this.data = it }
            type?.let { this.type = it }
        }
        .also { intent ->
            packageManager?.let {
                if (intent.resolveActivity(it) != null)
                    startActivity(intent)
                else
                    showToast(R.string.application_not_found)
            }
        }
}

My targetSdkVersion is 30. It gives me a warning in intent.resolveActivity(it):

Consider adding a queries declaration to your manifest when calling this method.

So What should I do to solve this warning?

over 4 years ago · Hanz Gallego
3 Respuestas
Responde la pregunta

0

The simplest solution is to get rid of resolveActivity(). Replace:

            packageManager?.let {
                if (intent.resolveActivity(it) != null)
                    startActivity(intent)
                else
                    showToast(R.string.application_not_found)
            }

with:

            try {
                startActivity(intent)
            } catch (ex: ActivityNotFoundException) {
                showToast(R.string.application_not_found)
            }

This gives you the same result with a bit better performance, and it will get rid of the warning.

Another option would be to add the QUERY_ALL_PACKAGES permission. This may get you banned from the Play Store.

Otherwise, you will need to:

  • Build a list of every possible openIntent() call that your app may make

  • Add a <queries> element to your manifest that lists all of those possible Intent structures that you want to be able to use with resolveActivity()

  • Repeat this process periodically, in case you add new scenarios for openIntent()

over 4 years ago · Hanz Gallego Denunciar

0

So starting Android 11 (i.e, if your app targets Android 11) not all applications will be visible to your application. Some apps are visible by default but in order to access other applications through your application, you will have to declare queries in your manifest else your application will not be able to access them. You can read about that here.

So if your application targets Android 11 and is to access an application that may not be visible by default you will want to add queries for them in the manifest file.

In your case, this warning is not applicable as I believe you are using implicit intents to open other applications. Using implicit intents, other applications can be accessed irrespective of app visibility. If your app target Android 10 or lower you can suppress the warning as all apps are visible by default.

To suppress the lint warning you can either:

  1. Add the suppress annotation, like so:
@SuppressLint("QueryPermissionsNeeded")
fun Activity.openIntent(action: String?, type: String?, uri: Uri?): Activity {
  1. Add the following to your android block in your app module build gradle file:
lintOptions {
    ignore "QueryPermissionsNeeded"
}
over 4 years ago · Hanz Gallego Denunciar

0

Replace

if (intent.resolveActivity(it) != null)

with

if (it.resolveActivity(intent, 0) != null)

and the warning will be gone.

over 4 years ago · Hanz Gallego Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda