Android 앱에서 Google Play 서비스로 구동되는 API에 액세스하려면 API 클라이언트 객체를 사용해야 합니다. 이러한 객체는 Google Play 서비스에 대한 연결을 처리하고, 연결이 가능할 때 요청을 대기열에 추가하고 순서대로 실행합니다. API 클라이언트는 저렴한 비용으로 구성할 수 있으므로 필요에 따라 새로 만들 수 있습니다.
승인이 필요하지 않은 서비스에 액세스하려면 서비스의 클라이언트 객체 인스턴스를 만들고 Context 또는 Activity 객체를 전달합니다. 필요한 경우 API 호출이 실행되기 전에 사용자에게 Google Play 서비스를 업그레이드하라는 메시지가 표시됩니다.
다음 코드 스니펫은 Fused Location Provider를 사용하여 기기의 마지막으로 알려진 위치를 가져오는 방법을 보여줍니다.
Kotlin
// Code required for requesting location permissions omitted for brevity.valclient=LocationServices.getFusedLocationProviderClient(this)// Get the last known location. In some rare situations, this can be null.client.lastLocation.addOnSuccessListener{location:Location? ->
location?.let{// Logic to handle location object.}}
자바
// Code required for requesting location permissions omitted for brevity.FusedLocationProviderClientclient=LocationServices.getFusedLocationProviderClient(this);// Get the last known location. In some rare situations, this can be null.client.getLastLocation().addOnSuccessListener(this,location->{if(location!=null){// Logic to handle location object.}});
[[["이해하기 쉬움","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-09-13(UTC)"],[[["\u003cp\u003eTo use Google Play services APIs, create API client objects which manage the connection and queue requests when offline.\u003c/p\u003e\n"],["\u003cp\u003eAccess services without authorization by obtaining the client object using the current \u003ccode\u003eContext\u003c/code\u003e or \u003ccode\u003eActivity\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAccess services requiring authorization by signing in the user, requesting necessary permissions, and then getting the client object.\u003c/p\u003e\n"],["\u003cp\u003eCheck for API availability using \u003ccode\u003echeckApiAvailability()\u003c/code\u003e if you need to disable features when an API is unavailable, although API calls will fail gracefully if the API isn't present.\u003c/p\u003e\n"]]],["To use Google Play services APIs, create an API client object, which manages the connection and queues requests. For services not requiring authorization, obtain the client instance using `Context` or `Activity`; for example, the Fused Location Provider client. For services requiring authorization, sign the user in, request necessary permissions, and then get the client using `GoogleSignInAccount`. For example, the Fit API client to get the daily steps. Before making API calls check with `checkApiAvailability()`.\n"],null,[]]