הגבלות על מיקום ברקע
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי לצמצם את צריכת החשמל, בגרסה 8.0 של Android (רמת API 26) מוגבלת התדירות שבה אפליקציה יכולה לאחזר את המיקום הנוכחי של המשתמש בזמן שהאפליקציה פועלת ברקע. בתנאים האלה, האפליקציות יכולות לקבל עדכוני מיקום רק כמה פעמים בכל שעה.
הערה: המגבלות האלה חלות על כל האפליקציות שמשמשות במכשירים שפועלת בהם גרסת Android 8.0 (רמת API 26) ואילך, ללא קשר לגרסה של ה-SDK לטירגוט של האפליקציה.
חשוב לזכור את אופן אחזור המיקום הזה במיוחד אם האפליקציה שלכם מסתמכת על התראות בזמן אמת או על זיהוי תנועה בזמן שהיא פועלת ברקע.
התנהגות האפליקציה שפועלת בחזית נשמרת
אם אפליקציה נמצאת בחזית במכשיר עם Android 8.0 (רמת API 26), התנהגות עדכון המיקום זהה לזו של Android 7.1.1 (רמת API 25) וגרסאות ישנות יותר.
אזהרה: אם האפליקציה שלכם מאחזרת עדכוני מיקום בזמן אמת לאורך זמן רב, חיי הסוללה של המכשיר קצרים יותר באופן משמעותי.
שינוי התנהגות האפליקציה בנושא מיקום
כדאי לבדוק אם תרחישי השימוש של האפליקציה לצורך הפעלה ברקע לא יכולים לפעול בכלל אם האפליקציה מקבלת עדכוני מיקום בתדירות נמוכה. במקרה כזה, תוכלו לאחזר עדכוני מיקום בתדירות גבוהה יותר באחת מהדרכים הבאות:
- מעבירים את האפליקציה לחזית.
-
כדי להפעיל שירות שפועל בחזית באפליקציה, צריך לבצע קריאה ל-startForegroundService()
. כששירות כזה בחזית פעיל, הוא מופיע כהתראה מתמשכת באזור ההתראות.
זהירות: אם האפליקציה מפעילה שירות בחזית בזמן שהיא פועלת ברקע במכשיר עם Android 11 (רמת API 30) ואילך, האפליקציה לא יכולה לגשת למידע על המיקום אלא אם המשתמש העניק לאפליקציה את ההרשאה ACCESS_BACKGROUND_LOCATION
. למידע נוסף, אפשר לעיין בהנחיות לגבי ההגבלות במהלך השימוש שמשויכות לשירותים שפועלים בחזית.
-
להשתמש ברכיבים של Geofencing API, כמו
GeofencingClient
, שעברו אופטימיזציה לצמצום צריכת החשמל.
-
להשתמש בבורר מיקום פסיבי, שעשוי לקבל עדכוני מיקום מהר יותר אם יש אפליקציות בחזית שמבקשות עדכוני מיקום בקצב מהיר יותר.
הערה: אם לאפליקציה שלכם דרושה גישה להיסטוריית המיקומים שמכילה עדכונים תדירים, השתמשו בגרסה האוספת של רכיבי Fused Location Provider API, כמו הממשק FusedLocationProviderApi
. כשהאפליקציה פועלת ברקע, ה-API הזה מקבל את המיקום של המשתמש בתדירות גבוהה יותר מאשר ה-API ללא אשכולות. עם זאת, חשוב לזכור שהאפליקציה עדיין מקבלת עדכונים בקבוצות רק כמה פעמים בכל שעה.
ממשקי ה-API שהושפעו
השינויים בהתנהגות אחזור המיקום באפליקציות ברקע משפיעים על ממשקי ה-API הבאים:
- ספק מיקום משולב (FLP)
-
-
אם האפליקציה פועלת ברקע, שירות מערכת המיקום מחשב מיקום חדש לאפליקציה רק כמה פעמים בכל שעה. המצב הזה נכון גם אם האפליקציה מבקשת עדכוני מיקום בתדירות גבוהה יותר.
עם זאת, אם משתמשים ב
גרסה של FLP עם קבוצות נתונים, יש לכם גישה להיסטוריית מיקומים בתדירות גבוהה יותר לאחר שהאפליקציה מקבלת עדכון קבוצתי, שמתרחש גם הוא רק כמה פעמים בכל שעה.
- אם האפליקציה פועלת בחזית, אין שינוי בשיעורי הדגימה של המיקום בהשוואה ל-Android 7.1.1 (רמת API 25).
- גבולות וירטואליים
-
- אפליקציות ברקע יכולות לקבל אירועי מעבר של גיאופיינס בתדירות גבוהה יותר מאשר עדכונים מספק המיקום המשולב.
- תגובה ממוצעת לאירוע של הגדרת גבולות גיאוגרפיים מתקבלת כל כמה דקות.
- מדידות GNSS והודעות ניווט של GNSS
-
- מנהל המיקומים
-
-
עדכוני המיקום מועברים לאפליקציות ברקע רק כמה פעמים בכל שעה.
הערה: אם האפליקציה פועלת במכשיר שבו מותקנים שירותי Google Play, מומלץ מאוד להשתמש ב-Fused Location Provider (FLP) במקום ב-Location Services.
- מנהל ה-Wi-Fi
-
ה-method
startScan()
מבצע סריקת מלא של אפליקציות ברקע רק כמה פעמים בכל שעה. אם אפליקציה ברקע קוראת שוב לשיטה זמן קצר לאחר מכן, הכיתה WifiManager
מספקת תוצאות שנשמרו במטמון מהסריקה הקודמת.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# Background Location Limits\n\nIn an effort to reduce power consumption, Android 8.0 (API level 26) limits\nhow frequently an app can retrieve the user's current location while the app is\n[running in the background](/guide/background). Under these\nconditions, apps can receive location updates only a few times each hour.\n\n**Note:** These limitations apply to all apps used on devices\nrunning Android 8.0 (API level 26) or higher, **regardless of an app's\ntarget SDK version**.\n\nThis location retrieval behavior is particularly\nimportant to keep in mind if your app relies on real-time alerts or motion\ndetection while running in the background.\n\nForeground app behavior is preserved\n------------------------------------\n\n\nIf an app is in the foreground on a device running Android 8.0 (API level 26),\nthe location update behavior is the same as on Android 7.1.1 (API level\n25) and lower.\n\n**Warning:** If your app retrieves near real-time location\nupdates over a long period of time, the device's battery life becomes\nsignificantly shorter.\n\nTuning your app's location behavior\n-----------------------------------\n\nConsider whether your app's use cases for running in the background cannot\nsucceed at all if your app receives infrequent location updates. If this is the\ncase, you can retrieve location updates more frequently by performing one of the\nfollowing actions:\n\n- Bring your app to the foreground.\n- Start a [foreground\n service](/guide/components/foreground-services) in your app by calling\n [startForegroundService()](/reference/android/content/Context#startForegroundService(android.content.Intent)). When such a foreground service is active, it\n appears as an ongoing notification in the\n [notification\n area](/guide/topics/ui/notifiers/notifications).\n\n **Caution:** If your app starts a foreground service\n while running in the background on a device that runs Android 11 (API\n level 30) or higher, your app cannot access location information unless the\n user has granted the\n [`ACCESS_BACKGROUND_LOCATION`](/reference/android/Manifest.permission#ACCESS_BACKGROUND_LOCATION)\n permission to your app. For more information, view the guidance about the\n [while-in-use\n restrictions](/guide/components/foreground-services#while-in-use-restrictions) that are associated with foreground services.\n- Use elements of the Geofencing API, such as the [`GeofencingClient`](https://developers.google.com/android/reference/com/google/android/gms/location/GeofencingClient), which are optimized for minimizing power use.\n- Use a passive location listener, which may receive faster location updates if there are foreground apps requesting location updates at a faster rate.\n\n**Note:** If your app needs access to location history that\ncontains time-frequent updates, use the batched version of the Fused Location\nProvider API elements, such as the\n[`FusedLocationProviderApi`](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi)\ninterface. When your app is running in the background, this API receives the\nuser's location more frequently than the non-batched API. Keep in mind, however,\nthat your app still receives updates in batches only a few times each hour.\n\nAffected APIs\n-------------\n\n\nThe changes to location retrieval behavior in background apps affect the\nfollowing APIs:\n\n[Fused\nLocation Provider (FLP)](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi)\n:\n - If your app is running in the background, the location system service\n computes a new location for your app only a few times each hour. This\n is the case even when your app is requesting more frequent location\n updates.\n\n By using the\n [batched version](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest#setMaxWaitTime(long)) of FLP, however, you have access to more\n time-frequent location history after your app receives a batch update,\n which also occurs only a few times each hour.\n - If your app is running in the foreground, there is no change in location sampling rates compared to Android 7.1.1 (API level 25).\n\nGeofencing\n:\n - Background apps can receive geofencing transition events more frequently than updates from the Fused Location Provider.\n - The average responsiveness for a geofencing event is every couple of minutes or so.\n\nGNSS Measurements and GNSS Navigation Messages\n:\n - When your app is in the background, callbacks that are registered to receive outputs from [GnssMeasurement](/reference/android/location/GnssMeasurement) and [GnssNavigationMessage](/reference/android/location/GnssNavigationMessage) stop executing.\n\nLocation Manager\n:\n - Location updates are provided to background apps only a few times\n each hour.\n\n\n **Note:** If your app is running on a device with\n Google Play services installed, it is highly recommended that you use\n the [Fused\n Location Provider (FLP)](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi) instead.\n\nWi-Fi Manager\n:\n The [startScan()](/reference/android/net/wifi/WifiManager#startScan()) method\n performs a full scan for background apps only a few times each hour. If a\n background app calls the method again soon afterward, the\n [WifiManager](/reference/android/net/wifi/WifiManager) class provides cached results from the\n previous scan."]]