با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
استفاده از موقعیت مکانی پسزمینه میتواند به طور قابل توجهی بر عمر باتری تأثیر بگذارد. اندروید از محدودیتهایی برای جمعآوری موقعیت مکانی پسزمینه پشتیبانی میکند و توسعهدهندگان را ترغیب میکند تا برنامههای خود را برای کارایی بهتر باتری بهینه کنند. این بهینه سازی ها برای همه دستگاه ها، صرف نظر از نسخه اندرویدی که در حال اجرا هستند، مفید است.
ارائه دهنده مکان فیوز شده. این API سیگنال های GPS، Wi-Fi و شبکه های سلولی و همچنین شتاب سنج، ژیروسکوپ، مغناطیس سنج و سایر حسگرها را ترکیب می کند.
Geofencing ، این API بر روی Fused Location Provider API ساخته شده است و برای عملکرد باتری بهینه شده است.
تخلیه باتری را درک کنید
جمع آوری مکان و تخلیه باتری به شرح زیر مرتبط است:
دقت: دقت داده های مکان. به طور کلی، هرچه دقت بالاتر باشد، تخلیه باتری بیشتر است.
فرکانس: هر چند وقت یکبار مکان محاسبه می شود. هر چه مکان مکرر محاسبه شود، باتری بیشتری مصرف می شود.
تأخیر: اطلاعات مکان با چه سرعتی تحویل داده می شود. تأخیر کمتر معمولاً به باتری بیشتری نیاز دارد.
دقت
می توانید دقت مکان را با استفاده از متد setPriority() مشخص کنید و یکی از مقادیر زیر را به عنوان آرگومان ارسال کنید:
PRIORITY_HIGH_ACCURACY دقیق ترین مکان ممکن را ارائه می دهد که با استفاده از ورودی های مورد نیاز محاسبه می شود (GPS، Wi-Fi و سلول را فعال می کند و از انواع سنسورها استفاده می کند) و ممکن است باعث تخلیه قابل توجه باتری شود.
PRIORITY_BALANCED_POWER_ACCURACY موقعیت مکانی دقیق را در عین بهینه سازی برای قدرت فراهم می کند. به ندرت از GPS استفاده می کند. معمولاً از ترکیبی از Wi-Fi و اطلاعات سلولی برای محاسبه مکان دستگاه استفاده می کند.
PRIORITY_LOW_POWER تا حد زیادی به دکلهای سلولی متکی است و از ورودیهای GPS و Wi-Fi اجتناب میکند و دقت درشت (در سطح شهر) را با حداقل تخلیه باتری ارائه میکند.
PRIORITY_NO_POWER مکان ها را به صورت غیرفعال از برنامه های دیگر دریافت می کند که مکان قبلاً برای آنها محاسبه شده است.
برای برآوردن نیازهای مکان اکثر برنامه ها از گزینه های قدرت متعادل یا کم مصرف استفاده کنید. دقت بالایی را برای برنامههایی که در پیشزمینه اجرا میشوند و به بهروزرسانیهای لحظهای مکان نیاز دارند (مثلاً یک برنامه نقشهبرداری) در نظر بگیرید.
فرکانس
می توانید فرکانس مکان را با استفاده از دو روش مشخص کنید:
از متد setIntervalMillis() برای تعیین فاصله زمانی برای محاسبه مکان برنامه خود استفاده کنید.
هنگام استفاده از setIntervalMillis() بزرگترین مقدار ممکن را ارسال کنید. این امر به ویژه برای جمع آوری مکان در پس زمینه، که اغلب باتری را تخلیه می کند، صادق است. فواصل چند ثانیه ای را برای موارد استفاده پیش زمینه رزرو کنید.
محدودیتهای موقعیت مکانی پسزمینه معرفیشده در Android 8.0 (سطح API 26) این استراتژیها را اعمال میکنند، اما برنامه شما باید تلاش کند تا آنها را در دستگاههای دارای Android 7.0 (سطح API 24) و پایینتر اعمال کند.
تأخیر
شما می توانید تاخیر را با استفاده از متد setMaxUpdateDelayMillis() مشخص کنید، معمولا مقداری را ارسال می کند که چندین برابر بیشتر از بازه مشخص شده در متد setIntervalMillis() است. این تنظیم تحویل مکان را به تأخیر میاندازد و ممکن است چندین بهروزرسانی مکان به صورت دستهای ارائه شود. این دو تغییر به کاهش مصرف باتری کمک می کند.
اگر برنامه شما فوراً به بهروزرسانی موقعیت مکانی نیاز ندارد، باید بیشترین مقدار ممکن را به متد setMaxUpdateDelayMillis() منتقل کنید، و به طور موثر تاخیر را برای دادهها و کارایی باتری بیشتر مبادله کنید.
هنگام استفاده از geofences، برنامه ها باید مقدار زیادی را به متد setNotificationResponsiveness() ارسال کنند تا قدرت حفظ شود. مقدار پنج دقیقه یا بیشتر توصیه می شود.
در ادامه مطلب
برای اطلاعات بیشتر به اسناد زیر مراجعه کنید:
توصیه ها : این راهنما برخی از اقدامات توصیه شده مشخص را ارائه می دهد که می توانید از آنها برای بهبود تأثیر برنامه خود بر عمر باتری استفاده کنید.
موارد استفاده : این راهنما چندین مورد استفاده متداول را ارائه می دهد که ممکن است از خدمات مکان استفاده کنید و چگونه می توانید تأثیر آن بر عمر باتری را برای آن موارد بهینه کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# About background location and battery life\n\nBackground location usage can significantly impact battery life. Android\nsupports limits to background location gathering, prompting developers to\noptimize their applications for better battery efficiency. These optimizations\nare beneficial for all devices, regardless of the Android version they are\nrunning.\n\nWith [Background Location Limits](/about/versions/oreo/background-location-limits):\n\n- Background location gathering is throttled and location is computed, and delivered only a few times an hour.\n- Wi-Fi scans are more conservative, and location updates aren't computed when the device stays connected to the same static access point.\n- Geofencing responsiveness changes from tens of seconds to approximately two minutes. This change improves battery performance---up to 10 times better on some devices.\n\n| **Note:** These features were first introduced with Android 8.0 (API level 26).\n\nRequired knowledge\n------------------\n\nThis document assumes familiarity with the following APIs:\n\n- [Google Location Services.](https://developers.google.com/android/reference/com/google/android/gms/location/package-summary.html) These APIs offer higher accuracy and impose a lighter battery burden than the [framework location APIs](/reference/android/location/package-summary).\n- [Fused Location Provider.](https://developers.google.com/location-context/fused-location-provider/) This API combines signals from GPS, Wi-Fi, and cell networks, as well as accelerometer, gyroscope, magnetometer and other sensors.\n- [Geofencing](https://developers.google.com/location-context/geofencing/), This API is built on top of the Fused Location Provider API, and is optimized for battery performance.\n\nUnderstand battery drain\n------------------------\n\nLocation gathering and battery drain are related as follows:\n\n- **Accuracy:** The precision of the location data. In general, the higher the accuracy, the higher the battery drain.\n- **Frequency:** How often location is computed. The more frequent location is computed, the more battery is used.\n- **Latency:** How quickly location data is delivered. Less latency usually requires more battery.\n\n### Accuracy\n\nYou can specify location accuracy using the [`setPriority()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setpriority-int-priority) method, passing\none of the following values as the argument:\n\n- [`PRIORITY_HIGH_ACCURACY`](https://developers.google.com/android/reference/com/google/android/gms/location/Priority#public-static-final-int-priority_high_accuracy) provides the most accurate location possible, which is computed using as many inputs as necessary (it enables GPS, Wi-Fi, and cell, and uses a variety of [Sensors](/guide/topics/sensors/sensors_overview)), and may cause significant battery drain.\n- [`PRIORITY_BALANCED_POWER_ACCURACY`](https://developers.google.com/android/reference/com/google/android/gms/location/Priority#public-static-final-int-priority_balanced_power_accuracy) provides accurate location while optimizing for power. Very rarely uses GPS. Typically uses a combination of Wi-Fi and cell information to compute device location.\n- [`PRIORITY_LOW_POWER`](https://developers.google.com/android/reference/com/google/android/gms/location/Priority#public-static-final-int-priority_low_power) largely relies on cell towers and avoids GPS and Wi-Fi inputs, providing coarse (city-level) accuracy with minimal battery drain.\n- [`PRIORITY_NO_POWER`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#PRIORITY_NO_POWER) receives locations passively from other apps for which location has already been computed.\n\nUse the balanced power or low power options to satisfy the location needs of\nmost apps. Reserve high accuracy for apps that run in the foreground and require\n*real time* location updates (for example, a mapping app).\n\n### Frequency\n\nYou can specify location frequency using two methods:\n\n- Use the [`setIntervalMillis()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setintervalmillis-long-intervalmillis) method to specify the interval for computing your app's location.\n- Use the [`setMinUpdateIntervalMillis()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setminupdateintervalmillis-long-minupdateintervalmillis) method to specify the interval for receiving other apps' locations.\n\nPass the largest possible value when using `setIntervalMillis()`. This is\nespecially true for background location gathering, which often drains the\nbattery. Reserve intervals of a few seconds for foreground use cases.\n\nThe background location limits introduced in Android 8.0 (API level 26) enforce\nthese strategies, but your app should strive to enforce them on devices running\nAndroid 7.0 (API level 24) and lower.\n\n### Latency\n\nYou can specify latency using the [`setMaxUpdateDelayMillis()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setmaxupdatedelaymillis-long-maxupdatedelaymillis) method,\ntypically passing a value that is several times larger than the interval\nspecified in the [`setIntervalMillis()`](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder#public-locationrequest.builder-setintervalmillis-long-intervalmillis) method. This setting delays\nlocation delivery, and multiple location updates may be delivered in batches.\nThese two changes help minimize battery consumption.\n\nIf your app doesn't immediately need a location update, you should pass the\nlargest possible value to the `setMaxUpdateDelayMillis()` method, effectively\ntrading latency for more data and battery efficiency.\n\nWhen using geofences, apps should pass a large value into the\n[`setNotificationResponsiveness()`](https://developers.google.com/android/reference/com/google/android/gms/location/Geofence.Builder.html#setNotificationResponsiveness(int)) method to preserve power. A value of\nfive minutes or larger is recommended.\n\nFurther reading\n---------------\n\nFor more information, see the following documents:\n\n- [Recommendations](/develop/sensors-and-location/location/battery/optimize): This guide lays out some concrete recommended actions you can use to improve your app's impact on battery life.\n- [Use cases](/develop/sensors-and-location/location/battery/scenarios): This guide provides several common use cases where you might use location services and how you could optimise the impact on battery life for those cases."]]