A partire dal 27 marzo 2025, ti consigliamo di utilizzare android-latest-release
anziché aosp-main
per compilare e contribuire ad AOSP. Per ulteriori informazioni, vedi Modifiche ad AOSP.
Limitare le località opportunistiche
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Quando un'app richiede la posizione di un dispositivo, può attendere la risposta alla richiesta o, utilizzando gli ascoltatori della posizione attivi, ricevere un aggiornamento della posizione opportunistico. Questa opzione era disponibile (senza restrizioni) su Android 9 e versioni precedenti ed era fornita quando un'app specificava solo la frequenza di aggiornamento della posizione attiva, lasciando vuota la frequenza passiva.
Gli ascoltatori della posizione passivi non ricevono aggiornamenti sulla posizione opportunistici perché non specificano una frequenza di aggiornamento della posizione.
A partire da Android 10, per ricevere aggiornamenti della posizione opportunistici, gli sviluppatori devono specificare che hanno bisogno di aggiornamenti della posizione passivi dalla classe FusedLocationProviderClient
.
Fused Location Provider
Le app possono specificare la frequenza con cui ricevono aggiornamenti sulla posizione opportunistici dalla classe FusedLocationProviderClient
in due modi.
- Specifica un valore nel metodo
setFastestInterval
inferiore al valore del parametro
setInterval
. Utilizza un valore pari o superiore a 0 ms.
- Lascia che il valore venga impostato automaticamente lasciando
setFastestInterval
non specificato.
Impatto
Se non fornisci un valore per setFastestInterval
,
la tua app potrebbe registrare una significativa
riduzione degli aggiornamenti della posizione inviati.
Implementazione
Per implementare questa funzionalità non devi fare altro che utilizzare i valori suggeriti per il metodo FusedLocationProviderClient
della classe setFastestInterval
.
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-27 UTC."],[],[],null,["# Restrict opportunistic locations\n\nWhen an app requests a device's location, it can either wait for\nthe request response or, by using active location listeners, get an\nopportunistic location update. This was available (unrestricted) in\nAndroid 9 and lower, and was provided when an app specified only\nthe active location update rate, leaving the passive rate blank.\n(Passive location listeners don't receive opportunistic location\nupdates because they don't specify a location update rate.)\n\nStarting in Android 10, to get opportunistic\nlocation updates, developers must specify that they need passive location\nupdates from the **[FusedLocationProviderClient](https://developers.google.com/android/reference/com/google/android/gms/location\n/FusedLocationProviderClient)** class.\n\nFused location provider\n-----------------------\n\nApps can specify the rate at which they get opportunistic location updates from the [FusedLocationProviderClient](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient)\nclass in two ways.\n\n- Specify a value in the [setFastestInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long)) method that's lower than the value of the [setInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setInterval(long)) parameter. (Use a value of 0 ms or greater.)\n- Let the value be set automatically by leaving [setFastestInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long)) unspecified.\n\nImpact\n------\n\nIf you don't provide a value for [setFastestInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long)),\nyour app may experience a significant\nreduction in location updates delivered to it.\n\nImplementation\n--------------\n\nYou don't need to do anything to implement this feature other\nthan to use the suggested values for the [FusedLocationProviderClient](https://developers.google.com/android/reference/com/google/android/gms/location\n/FusedLocationProviderClient) class [setFastestInterval](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setFastestInterval(long))\nmethod."]]