Thay đổi đối với các loại dịch vụ trên nền trước cho Android 15
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Chúng tôi sẽ thực hiện những thay đổi sau đây đối với các loại dịch vụ trên nền trước trong Android 15.
- Loại dịch vụ trên nền trước cần khai báo trong tệp kê khai theo
android:foregroundServiceType
mediaProcessing
- Quyền khai báo trong tệp kê khai
FOREGROUND_SERVICE_MEDIA_PROCESSING
- Hằng số để truyền đến
startForeground()
FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING
- Điều kiện tiên quyết về thời gian chạy
- Không có
- Mô tả
Dịch vụ để thực hiện các thao tác tốn thời gian trên các thành phần nội dung nghe nhìn, chẳng hạn như chuyển đổi nội dung nghe nhìn sang nhiều định dạng. Hệ thống cho phép dịch vụ này chạy trong một khoảng thời gian giới hạn; trong trường hợp bình thường, giới hạn thời gian này sẽ là 6 giờ trong mỗi 24 giờ. (Tất cả dịch vụ mediaProcessing
trên nền trước của ứng dụng đều dùng chung giới hạn này.)
Ứng dụng của bạn nên dừng dịch vụ xử lý nội dung nghe nhìn theo cách thủ công trong trường hợp sau:
Nếu hết thời gian chờ, hệ thống sẽ gọi phương thức Service.onTimeout(int, int)
của dịch vụ. Tại thời điểm này, dịch vụ có vài giây để gọi Service.stopSelf()
. Nếu dịch vụ không gọi Service.stopSelf()
, thì lỗi ANR sẽ xảy ra kèm theo thông báo lỗi này: "Dịch vụ trên nền trước của <fgs_type> không dừng trong thời gian chờ: <component_name>".
Lưu ý: Service.onTimeout(int, int)
không dùng được trên Android 14 trở xuống. Trên các thiết bị chạy các phiên bản đó, nếu một dịch vụ xử lý nội dung nghe nhìn đạt đến khoảng thời gian chờ, thì hệ thống sẽ ngay lập tức lưu ứng dụng vào bộ nhớ đệm. Vì lý do này, ứng dụng của bạn không nên đợi nhận thông báo hết thời gian chờ.
Thay vào đó, ứng dụng phải chấm dứt dịch vụ trên nền trước hoặc thay đổi dịch vụ đó thành dịch vụ trên nền ngay khi thích hợp.
Camera
Các ứng dụng nhắm đến Android 15 trở lên không được phép chạy dịch vụ trên nền trước của máy ảnh từ bộ nhận tín hiệu truyền tin BOOT_COMPLETED
.
Để biết thêm thông tin, hãy xem phần Hạn chế đối với broadcast receiver BOOT_COMPLETED
khởi chạy dịch vụ trên nền trước.
Đồng bộ hoá dữ liệu
Các ứng dụng nhắm đến Android 15 trở lên không được phép chạy dịch vụ đồng bộ hoá dữ liệu trên nền trước từ bộ nhận tín hiệu truyền tin BOOT_COMPLETED
.
Để biết thêm thông tin, hãy xem phần Hạn chế đối với broadcast receiver BOOT_COMPLETED
khởi chạy dịch vụ trên nền trước.
Các ứng dụng nhắm đến Android 15 trở lên không được phép chạy dịch vụ phát nội dung đa phương tiện trên nền trước từ trình nhận thông báo truyền tin BOOT_COMPLETED
.
Để biết thêm thông tin, hãy xem phần Hạn chế đối với broadcast receiver BOOT_COMPLETED
khởi chạy dịch vụ trên nền trước.
Các ứng dụng nhắm đến Android 15 trở lên không được phép chạy dịch vụ trên nền trước của tính năng chiếu nội dung đa phương tiện từ một trình nhận thông báo truyền tin BOOT_COMPLETED
.
Để biết thêm thông tin, hãy xem phần Hạn chế đối với broadcast receiver BOOT_COMPLETED
khởi chạy dịch vụ trên nền trước.
Micrô
Các ứng dụng nhắm đến Android 14 (API cấp 34) trở lên không được phép chạy dịch vụ trên nền trước của micrô từ trình nhận thông báo truyền tin BOOT_COMPLETED
.
Để biết thêm thông tin, hãy xem phần Hạn chế đối với broadcast receiver BOOT_COMPLETED
khởi chạy dịch vụ trên nền trước.
Cuộc gọi điện thoại
Các ứng dụng nhắm đến Android 15 trở lên không được phép chạy dịch vụ trên nền trước của cuộc gọi điện thoại từ một trình nhận thông báo truyền tin BOOT_COMPLETED
.
Để biết thêm thông tin, hãy xem phần Hạn chế đối với broadcast receiver BOOT_COMPLETED
khởi chạy dịch vụ trên nền trước.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Changes to foreground service types for Android 15\n\nWe are making the following changes to foreground service types with Android\n15.\n\n### Media processing\n\nForeground service type to declare in manifest under\n`android:foregroundServiceType`\n: `mediaProcessing`\n\nPermission to declare in your manifest\n: `FOREGROUND_SERVICE_MEDIA_PROCESSING`\n\nConstant to pass to `startForeground()`\n: `FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING`\n\nRuntime prerequisites\n: None\n\nDescription\n\n: Service for performing time-consuming operations on media assets, like\n converting media to different formats. The system allows this service a limited\n time to run; under normal circumstances, this time limit would be 6 hours out of\n every 24. (This limit is shared by all of an app's `mediaProcessing` foreground\n services.)\n\n: Your app should manually stop the media processing service in the following\n scenario:\n\n - When the transcoding operation finishes or reaches a failure state, have the service call [`Service.stopForeground()`](/reference/android/app/Service#stopForeground(int)) and [`Service.stopSelf()`](/reference/android/app/Service#stopSelf()) to stop the service completely.\n\n: If the timeout period is reached, the system calls the service's\n [`Service.onTimeout(int, int)`](/reference/android/app/Service#onTimeout(int,%20int)) method. At this\n time, the service has a few\n seconds to call [`Service.stopSelf()`](/reference/android/app/Service#stopSelf()). If the service does not call\n `Service.stopSelf()`, an ANR will occur with this error message: \"A\n foreground service of *\\\u003cfgs_type\\\u003e* did not stop within its\n timeout: *\\\u003ccomponent_name\\\u003e*\".\n\n **Note** : `Service.onTimeout(int, int)` is not available on Android 14\n or lower. On devices running those versions, if a media processing\n service reaches the timeout period, the system immediately caches the app.\n For this reason, your app shouldn't wait to get a timeout notification.\n Instead, it should terminate the foreground service or change it to a\n background service as soon as appropriate.\n\n### Camera\n\nApps that target Android 15 or higher are not allowed to launch a\ncamera foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Data sync\n\nApps that target Android 15 or higher are not allowed to launch a\ndata sync foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Media playback\n\nApps that target Android 15 or higher are not allowed to launch a\nmedia playback foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Media projection\n\nApps that target Android 15 or higher are not allowed to launch a\nmedia projection foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Microphone\n\nApps that target Android 14 (API level 34) or higher are not allowed to launch a\nmicrophone foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n\n### Phone call\n\nApps that target Android 15 or higher are not allowed to launch a\nphone call foreground service from a `BOOT_COMPLETED` broadcast receiver.\nFor more information, see\n[Restrictions on `BOOT_COMPLETED` broadcast receivers launching foreground\nservices](/about/versions/15/behavior-changes-15#fgs-boot-completed)."]]