Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Para acessar
APIs com tecnologia do Google Play Services
no seu app Android, use objetos de cliente da API. Esses objetos processam
a conexão com o Google Play Services, enfileirando e executando solicitações em
ordem quando uma conexão está disponível. Você pode criar novos clientes de API conforme necessário, já que eles têm baixo custo de construção.
Para acessar um serviço que não exige autorização, crie uma instância do
objeto cliente do serviço, transmitindo um objeto
Context ou
Activity. Se necessário, os usuários vão receber uma solicitação para atualizar o Google Play Services antes da execução de qualquer chamada de API.
O snippet de código a seguir mostra como conseguir a última localização conhecida do dispositivo
usando o provedor de localização combinada:
Kotlin
// Code required for requesting location permissions omitted for brevity.valclient=LocationServices.getFusedLocationProviderClient(this)// Get the last known location. In some rare situations, this can be null.client.lastLocation.addOnSuccessListener{location:Location? ->
location?.let{// Logic to handle location object.}}
Java
// Code required for requesting location permissions omitted for brevity.FusedLocationProviderClientclient=LocationServices.getFusedLocationProviderClient(this);// Get the last known location. In some rare situations, this can be null.client.getLastLocation().addOnSuccessListener(this,location->{if(location!=null){// Logic to handle location object.}});
Antes de ativar um recurso que depende de uma API do Google Play Services, verifique se
a API está disponível no dispositivo chamando
checkApiAvailability().
O snippet de código a seguir mostra como verificar se o provedor de localização combinada está
disponível:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-10 UTC."],[[["\u003cp\u003eTo use Google Play services APIs, create API client objects which manage the connection and queue requests when offline.\u003c/p\u003e\n"],["\u003cp\u003eAccess services without authorization by obtaining the client object using the current \u003ccode\u003eContext\u003c/code\u003e or \u003ccode\u003eActivity\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAccess services requiring authorization by signing in the user, requesting necessary permissions, and then getting the client object.\u003c/p\u003e\n"],["\u003cp\u003eCheck for API availability using \u003ccode\u003echeckApiAvailability()\u003c/code\u003e if you need to disable features when an API is unavailable, although API calls will fail gracefully if the API isn't present.\u003c/p\u003e\n"]]],["To use Google Play services APIs, create an API client object, which manages the connection and queues requests. For services not requiring authorization, obtain the client instance using `Context` or `Activity`; for example, the Fused Location Provider client. For services requiring authorization, sign the user in, request necessary permissions, and then get the client using `GoogleSignInAccount`. For example, the Fit API client to get the daily steps. Before making API calls check with `checkApiAvailability()`.\n"],null,[]]