Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

643
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda