Android 위치 버튼은 세션 범위의 정확한 위치 액세스를 요청하는 방법을 간소화하도록 설계된 맞춤설정 가능한 시스템 UI 요소입니다. 직접적인 사용자 작업을 통해 위치 요청을 시작하면 버튼이 사용자 개인 정보 보호를 개선하고 일반적으로 일시적인 '이번만' 부여에서 발생하는 반복적인 권한 대화상자의 마찰을 줄입니다.
앱이 Android 17 (API 수준 37) 이상을 타겟팅하고 작동하는 데 세션 기반 위치 액세스가 필요한 기능만 포함하는 경우 Google Play 정책에 따라 위치 버튼을 사용해야 합니다. 자세한 내용은 위치 버튼 정책을 참고하세요.
위치 버튼을 사용해야 하는 경우
일시적인 세션 기반 정확한 위치 액세스가 필요한 기능에 위치 버튼을 사용합니다. 이 방법은 지속적인 위치 액세스가 필요하지 않고 반복적인 '이번만' 권한 프롬프트를 줄이는 것을 목표로 하는 애플리케이션에 적합합니다.
일반적인 사용 사례는 다음과 같습니다.
- '내 주변 검색' 기능: 주변 호텔, 상점 또는 음식점을 찾습니다.
- 위치 공유: 현재 위치를 친구 또는 가족과 한 번 공유합니다.
- 소셜 미디어: 체크인 또는 위치 태그 지정
- 전자상거래: 배송 주소 자동 완성
UI 맞춤설정
버튼이 앱의 미적 감각과 일치하면서도 인식 가능하도록 하려면 다음 시각적 요소를 수정하면 됩니다.
- 배경 및 아이콘 색 구성표
- 윤곽선 스타일, 크기, 도형
- 미리 정의된 목록의 텍스트 라벨 (예: '정확한 위치 사용', '정확한 위치 공유')
위치 버튼 구현
위치 버튼을 통합하려면 Jetpack 라이브러리를 사용하세요. 이 라이브러리는 설정을 간소화하고, 최신 플랫폼에서 보안 렌더링을 처리하며, Android 16 이하를 타겟팅하는 앱에 대체 기능을 제공합니다.
1단계: Android 매니페스트에서 권한 선언
시스템의 원격 렌더링 서비스에 필요한 전용 USE_LOCATION_BUTTON 권한과 함께 표준 위치 권한을 선언해야 합니다.
<?xml version="1.0" encoding="utf-8"?> <!-- Copyright 2026 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 1. Standard Coarse and Fine Location Permissions --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- Optional: If your app is only using the location button to access location, you should add the "onlyForLocationButton" flag shown below to your ACCESS_FINE_LOCATION declaration. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:usesPermissionFlags="onlyForLocationButton"/> Note: Adding this flag restricts your app from accessing the precise location permission via the broader permission, and that users will be required to use the location button in order to share precise location with the app. This is designed to improve user privacy & trust when granting location access. --> <!-- 2. CRITICAL: Required system permission for rendering the LocationButton --> <uses-permission android:name="android.permission.USE_LOCATION_BUTTON" /> <application android:icon="@mipmap/ic_launcher" android:label="LocationButtonSample" android:theme="@style/Theme.PinPoint"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
2단계: Kotlin 컴포저블 구현
다음은 사용 가능한 맞춤설정 옵션 사용 예를 포함하여 위치 버튼의 구현 예입니다. 이러한 옵션을 사용하여 UI가 앱의 나머지 부분과 일치하도록 할 수 있습니다.
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.width import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.core.locationbutton.compose.LocationButton import androidx.core.locationbutton.compose.LocationButtonTextType @Composable fun LocationPermissionScreen(onPermissionGranted: () -> Unit, onPermissionDenied: () -> Unit) { // Renders the secure system-trusted Location Button composable LocationButton( // Callback triggered when the user taps the secure button and makes a decision on the permission dialog onPermissionResult = { isGranted -> if (isGranted) { onPermissionGranted() } else { onPermissionDenied() } }, /* ============================================================================ * VISUAL CUSTOMIZATIONS * Un-comment any of the parameters below to customize the button's aesthetics. * If omitted, the button falls back to secure, high-contrast system defaults. * ============================================================================ */ /* // LABEL TEXT TYPE: // Predefined system strings rendered inside the secure process. // Options: PreciseLocation, UsePreciseLocation, SharePreciseLocation, // NearMyPreciseLocation, or None (for an icon-only button). textType = LocationButtonTextType.UsePreciseLocation, // COLOR PALETTE: // Customize the container background, text label, and icon tint colors. backgroundColor = Color(0xFF00796B), // e.g., Material Teal textColor = Color.White, iconTint = Color(0xFFFFC107), // e.g., Amber icon tint // CORNER RADIUS & SHAPE: // Define the resting corner radius and the morphed radius when pressed. cornerRadius = 24.dp, // Rounded capsule shape pressedCornerRadius = 12.dp, // Morphs to sharper corners on tap // OUTLINE STROKE (BORDERS): // Add a contrasting outline stroke around the button bounds. strokeColor = Color(0xFF004D40), strokeWidth = 2.dp, // INTERACTIVE TOUCH PADDING: // Defines the secure clickable touch target boundary. // Coerced securely by the system between 4.dp and 8.dp. clickablePadding = PaddingValues(6.dp) */ ) }
3단계: 하위 호환성 처리
Jetpack 라이브러리는 이전 Android 버전에서 하위 호환성을 자동으로 처리합니다. Android 16 이하를 실행하는 기기에서 라이브러리는 맞춤설정된 시각적 레이아웃을 유지하지만 표준 위치 정보 액세스 권한 프롬프트를 트리거하도록 되돌리는 로컬 렌더링 구성요소로 대체됩니다.
이 접근 방식을 사용하면 Android 16 이하를 실행하는 기기를 위한 병렬 솔루션을 유지하지 않고도 위치 버튼을 채택하는 이점을 활용할 수 있습니다.