view.setOnApplyWindowInsetsListener{view,windowInsets->
valindicatorBounds=windowInsets.getPrivacyIndicatorBounds()// change your UI to avoid overlappingwindowInsets}
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Explain access to more sensitive information\n\nThe permissions related to location, microphone, and camera grant your app\naccess to particularly sensitive information about users. The platform includes\nseveral mechanisms, described on this page, to help users stay informed and in\ncontrol over which apps can access location, microphone, and camera.\n\nThese privacy-preserving system features shouldn't affect how your app handles\nthe permissions related to location, microphone, and camera, as long as you\n[follow privacy best practices](/privacy/best-practices).\n\nIn particular, make sure you do the following in your app:\n\n- Wait to access the device's camera until the user has granted the [`CAMERA`](/reference/android/Manifest.permission#CAMERA) permission to your app.\n- Wait to access the device's microphone until the user has granted the [`RECORD_AUDIO`](/reference/android/Manifest.permission#RECORD_AUDIO) permission to your app.\n- Wait until the user interacts with a feature in your app that requires location before you request the [`ACCESS_COARSE_LOCATION`](/reference/android/Manifest.permission#ACCESS_COARSE_LOCATION) permission or the [`ACCESS_FINE_LOCATION`](/reference/android/Manifest.permission#ACCESS_FINE_LOCATION) permission, as described in the guide on how to [request location\n permissions](/training/location/permissions#request-location-access-runtime).\n- Wait until the user grants your app either the `ACCESS_COARSE_LOCATION` permission or the `ACCESS_FINE_LOCATION` permission before you request the [`ACCESS_BACKGROUND_LOCATION`](/reference/android/Manifest.permission#ACCESS_BACKGROUND_LOCATION) permission.\n\nPrivacy Dashboard\n-----------------\n\n**Figure 1.** Location usage screen, part of the Privacy Dashboard.\n\nOn supported devices that run Android 12 or higher, a Privacy\nDashboard screen appears in system settings. On this screen, users can access\nseparate screens that show when apps access location, camera, and microphone\ninformation. Each screen shows a timeline of when different apps have accessed a\nparticular type of data. Figure 1 shows the data access timeline for location\ninformation.\n\n### Show rationale for data access\n\nYour app can provide a rationale for users to help them understand why your app\naccesses location, camera, or microphone information. This rationale can appear\non the new Privacy Dashboard screen, your app's permissions screen, or both.\n\nTo explain why your app accesses location, camera, and microphone information,\ncomplete the following steps:\n\n1. Add an activity that, when started, provides some rationale for why your app\n performs a particular type of data access action. Within this activity, set the\n [`android:permission`](/guide/topics/manifest/activity-element#prmsn) attribute\n to [`START_VIEW_PERMISSION_USAGE`](/reference/android/Manifest.permission#START_VIEW_PERMISSION_USAGE).\n\n If your app targets Android 12 or higher, you must explicitly\n [define a value for the `android:exported`\n attribute](/about/versions/12/behavior-changes-12#exported).\n2. Add the following intent filter to the newly-added activity:\n\n ```xml\n \u003c!-- android:exported required if you target Android 12. --\u003e\n \u003cactivity android:name=\".DataAccessRationaleActivity\"\n android:permission=\"android.permission.START_VIEW_PERMISSION_USAGE\"\n android:exported=\"true\"\u003e\n \u003c!-- VIEW_PERMISSION_USAGE shows a selectable information icon on\n your app permission's page in system settings.\n VIEW_PERMISSION_USAGE_FOR_PERIOD shows a selectable information\n icon on the Privacy Dashboard screen. --\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.intent.action.VIEW_PERMISSION_USAGE\" /\u003e\n \u003caction android:name=\"android.intent.action.VIEW_PERMISSION_USAGE_FOR_PERIOD\" /\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n ...\n \u003c/intent-filter\u003e\n \u003c/activity\u003e\n ```\n3. Decide what your data access rationale activity should show. For example, you\n might show your app's website or a help center article. To provide a more\n detailed explanation about the types of data that your app accesses, as well as\n when the access occurred, handle the extras that the system includes when it\n invokes the permission usage intent:\n\n - If the system invokes `ACTION_VIEW_PERMISSION_USAGE`, your app can retrieve a value for [`EXTRA_PERMISSION_GROUP_NAME`](/reference/android/content/Intent#EXTRA_PERMISSION_GROUP_NAME).\n - If the system invokes `ACTION_VIEW_PERMISSION_USAGE_FOR_PERIOD`, your app can retrieve values for `EXTRA_PERMISSION_GROUP_NAME`, [`EXTRA_ATTRIBUTION_TAGS`](/reference/android/content/Intent#EXTRA_ATTRIBUTION_TAGS), [`EXTRA_START_TIME`](/reference/android/content/Intent#EXTRA_START_TIME), and [`EXTRA_END_TIME`](/reference/android/content/Intent#EXTRA_END_TIME).\n\nDepending on which intent filters you add, users see an information icon\nnext to your app's name on certain screens:\n\n- If you add the intent filter that contains the `VIEW_PERMISSION_USAGE` action, users see the icon on your app's permissions page in system settings. You can apply this action to all runtime permissions.\n- If you add the intent filter that contains the `VIEW_PERMISSION_USAGE_FOR_PERIOD` action, users see the icon next to your app's name whenever your app appears in the Privacy Dashboard screen.\n\nWhen users select that icon, your app's rationale activity is started. \n**Figure 2.** Microphone and camera indicators, which show recent data access.\n\nIndicators\n----------\n\n| **Note:** The icon mentioned in this section shouldn't require changes to your app's logic, as long as you [follow privacy best\n| practices](/privacy/best-practices).\n\nOn devices that run Android 12 or higher, when an app accesses\nthe microphone or camera, an icon appears in the status bar. If the app is in\n[immersive mode](/training/system-ui/immersive#immersive), the icon appears in\nthe upper-right corner of the screen. Users can open Quick Settings and select\nthe icon to view which apps are currently using the microphone or camera.\nFigure 2 shows an example screenshot that contains the icons.\n\n### Identify the screen location of indicators\n\nIf your app supports immersive mode or a full-screen UI, the indicators might\nmomentarily overlap your app's UI. To help adapt your UI to these indicators,\nthe system introduces the\n[`getPrivacyIndicatorBounds()`](/reference/android/view/WindowInsets.Builder#setPrivacyIndicatorBounds(android.graphics.Rect))\nmethod, which the following code snippet demonstrates. Using this API, you can\nidentify the bounds where the indicators might appear. You might then decide to\norganize your screen's UI differently. \n\n### Kotlin\n\n```kotlin\nview.setOnApplyWindowInsetsListener { view, windowInsets -\u003e\n val indicatorBounds = windowInsets.getPrivacyIndicatorBounds()\n // change your UI to avoid overlapping\n windowInsets\n}\n```\n\nToggles\n-------\n\n| **Note:** The toggles mentioned in this section shouldn't require changes to your app's logic, as long as you [follow privacy best\npractices](/privacy/best-practices). \n**Figure 3.** Microphone and camera toggles in Quick Settings.\n\nOn [supported devices](#toggles-check-device-support) that run\nAndroid 12 or higher, users can enable and disable camera and\nmicrophone access for all apps on the device by pressing a single toggle\noption. Users can access the toggleable options from [Quick\nSettings](https://support.google.com/android/answer/9083864), as shown in\nfigure 3, or from the Privacy screen in system settings.\n\nThe camera and microphone toggles affect all apps on the device:\n\n- When the user turns off camera access, your app receives a blank camera feed.\n- When the user turns off microphone access, your app receives silent audio.\n Additionally, [motion sensors are\n rate-limited](/guide/topics/sensors/sensors_overview#sensors-rate-limiting),\n regardless of whether you declare the\n [`HIGH_SAMPLING_RATE_SENSORS`](/reference/android/Manifest.permission#HIGH_SAMPLING_RATE_SENSORS)\n permission.\n\n | **Note:** When the user places a call to emergency services, such as 911, the system turns on microphone access. This behavior preserves user safety.\n\nWhen the user turns off access to camera or microphone, then\nlaunches an app that needs access to camera or microphone information, the\nsystem reminds the user that the device-wide toggle is turned off.\n\n### Check device support\n\nTo check whether a device supports microphone and camera toggles, add the logic\nthat appears in the following code snippet: \n\n### Kotlin\n\n```kotlin\nval sensorPrivacyManager = applicationContext\n .getSystemService(SensorPrivacyManager::class.java)\n as SensorPrivacyManager\nval supportsMicrophoneToggle = sensorPrivacyManager\n .supportsSensorToggle(Sensors.MICROPHONE)\nval supportsCameraToggle = sensorPrivacyManager\n .supportsSensorToggle(Sensors.CAMERA)\n```\n\n### Java\n\n```java\nSensorPrivacyManager sensorPrivacyManager = getApplicationContext()\n .getSystemService(SensorPrivacyManager.class);\nboolean supportsMicrophoneToggle = sensorPrivacyManager\n .supportsSensorToggle(Sensors.MICROPHONE);\nboolean supportsCameraToggle = sensorPrivacyManager\n .supportsSensorToggle(Sensors.CAMERA);\n```"]]