Android 11 中的前景服務
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 11 變更了前景服務存取裝置位置資訊、相機和麥克風的時機。這有助於保護敏感的使用者資料。
- 攝影機和麥克風前景服務類型
- 如果應用程式適用於 Android 11 以上版本,且會透過前景服務存取相機或麥克風,就必須加入
camera
和 microphone
前景服務類型。 - 使用期間的存取限制
- 如果應用程式在背景執行時啟動前景服務,前景服務就無法存取麥克風或相機。此外,除非應用程式具有背景位置資訊存取權,否則服務無法存取位置資訊。
進一步瞭解如何在應用程式中使用前景服務。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[],[],null,["Android 11 changes when foreground services can\naccess the device's location, camera, and microphone. This helps protect\nsensitive user data.\n\nCamera and microphone foreground service types\n: If your app targets Android 11 or higher and accesses the\n camera or microphone in a foreground service, you must include the `camera` and\n `microphone` [foreground service\n types](/guide/components/foreground-services#types).\n\nRestrictions to access while in use\n: If your app [starts a foreground service while running in the\n background](/guide/components/foreground-services#while-in-use-restrictions), the\n foreground service cannot access the microphone or camera. Additionally,\n the service cannot access location unless your app\n has [background location](/training/location/permissions#background) access.\n\nLearn more about how to use [foreground\nservices](/guide/components/foreground-services) in your app."]]