Od 27 marca 2025 r. zalecamy używanie android-latest-release
zamiast aosp-main
do kompilowania i wspołtworzenia AOSP. Więcej informacji znajdziesz w artykule o zmianach w AOSP.
Ograniczanie lokalizacji domyślnych
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Gdy aplikacja poprosi o lokalizację urządzenia, może poczekać na odpowiedź na żądanie lub, korzystając z odbioru lokalizacji, uzyskać aktualizację lokalizacji w sposób okazjonalny. Była ona dostępna (bez ograniczeń) w Androidzie 9 i starszych wersjach, gdy aplikacja określiła tylko współczynnik częstotliwości aktualizacji aktywnej lokalizacji, pozostawiając pole dotyczące współczynnika częstotliwości aktualizacji w stanie pustym.
(pasywni słuchacze lokalizacji nie otrzymują losowych aktualizacji lokalizacji, ponieważ nie określają częstotliwości ich wysyłania).
Aby od Androida 10 móc otrzymywać aktualizacje lokalizacji w ramach możliwości, deweloperzy muszą wskazać, że potrzebują pasywnych aktualizacji lokalizacji z klasy FusedLocationProviderClient
.
dostawca uśrednionej lokalizacji,
Aplikacje mogą określać częstotliwość, z jaką otrzymują okazjonalne aktualizacje lokalizacji z klasy FusedLocationProviderClient
, na 2 sposoby.
Wpływ
Jeśli nie podasz wartości parametru setFastestInterval
, aplikacja może otrzymywać znacznie mniej aktualizacji lokalizacji.
Implementacja
Aby wdrożyć tę funkcję, nie musisz nic robić oprócz użycia sugerowanych wartości w metodie FusedLocationProviderClient
klasy setFastestInterval
.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-27 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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."]]