Play 설치 리퍼러 라이브러리
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Google Play 스토어의 Install Referrer API를 사용하여 Google Play에서 추천 콘텐츠를 안전하게 가져올 수 있습니다. Play Install Referrer API 클라이언트 라이브러리는 자바 프로그래밍 언어로 작성되며 설치 리퍼러 서비스의 인터페이스를 정의하는 Android 인터페이스 정의 언어(AIDL) 파일의 래퍼입니다. Play Install Referrer API 클라이언트 라이브러리를 사용하여 개발 프로세스를 간소화할 수 있습니다.
이 가이드에서는 Play 설치 리퍼러 라이브러리를 사용하여 Google Play에서 추천 정보를 가져오는 데 관한 기본 사항을 설명합니다.
앱의 종속 항목 업데이트
앱 build.gradle
파일의 종속 항목 섹션에 다음 줄을 추가합니다.
Groovy
dependencies {
...
implementation "com.android.installreferrer:installreferrer:2.2"
}
Kotlin
dependencies {
...
implementation("com.android.installreferrer:installreferrer:2.2")
}
Google Play에 연결
다음 단계를 사용하여 Play 스토어 앱과의 연결을 설정해야 Play Install Referrer API 라이브러리를 사용할 수 있습니다.
newBuilder()
메서드를 호출하여 InstallReferrerClient
클래스의 인스턴스를 만듭니다.
startConnection()
을 호출하여 Google Play와의 연결을 설정합니다.
startConnection()
메서드는 비동기식이므로 startConnection()
이 완료된 후 콜백을 수신하려면 InstallReferrerStateListener
를 재정의해야 합니다.
콜백이 완료될 때 알림을 받도록 onInstallReferrerSetupFinished()
메서드를 재정의합니다. 이 메서드는 응답 코드와 함께 호출되며 이를 사용하여 여러 상태를 처리해야 합니다.
OK
는 연결이 성공했음을 나타냅니다. 다른 각 InstallReferrerResponse
상수는 다양한 유형의 오류에 사용됩니다.
Google Play 연결이 중단된 경우를 처리하기 위해 onInstallReferrerServiceDisconnected()
메서드를 재정의합니다. 예를 들어, 백그라운드에서 Play 스토어 서비스를 업데이트한다면 Play 설치 리퍼러 라이브러리 클라이언트에서 연결이 끊어질 수 있습니다. 추가 요청을 하기 전에 연결을 다시 시작하려면 라이브러리 클라이언트에서 startConnection()
메서드를 호출해야 합니다.
다음 코드는 Play 스토어 앱 연결을 시작하고 테스트하는 방법을 보여줍니다.
Kotlin
private lateinit var referrerClient: InstallReferrerClient
referrerClient = InstallReferrerClient.newBuilder(this).build()
referrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
when (responseCode) {
InstallReferrerResponse.OK -> {
// Connection established.
}
InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
// API not available on the current Play Store app.
}
InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
// Connection couldn't be established.
}
}
}
override fun onInstallReferrerServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
})
자바
InstallReferrerClient referrerClient;
referrerClient = InstallReferrerClient.newBuilder(this).build();
referrerClient.startConnection(new InstallReferrerStateListener() {
@Override
public void onInstallReferrerSetupFinished(int responseCode) {
switch (responseCode) {
case InstallReferrerResponse.OK:
// Connection established.
break;
case InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
// API not available on the current Play Store app.
break;
case InstallReferrerResponse.SERVICE_UNAVAILABLE:
// Connection couldn't be established.
break;
}
}
@Override
public void onInstallReferrerServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
});
설치 리퍼러 가져오기
Play 스토어 앱에 연결을 설정한 후 다음 단계를 완료하여 설치 리퍼러에서 세부정보를 가져옵니다.
동기화된 getInstallReferrer()
메서드를 사용하여 ReferrerDetails
의 인스턴스를 반환합니다.
ReferrerDetails
클래스가 제공하는 메서드를 사용하여 설치 리퍼러에 관한 세부정보를 가져옵니다.
다음 코드는 설치 리퍼러 정보에 액세스하는 방법을 보여줍니다.
Kotlin
val response: ReferrerDetails = referrerClient.installReferrer
val referrerUrl: String = response.installReferrer
val referrerClickTime: Long = response.referrerClickTimestampSeconds
val appInstallTime: Long = response.installBeginTimestampSeconds
val instantExperienceLaunched: Boolean = response.googlePlayInstantParam
자바
ReferrerDetails response = referrerClient.getInstallReferrer();
String referrerUrl = response.getInstallReferrer();
long referrerClickTime = response.getReferrerClickTimestampSeconds();
long appInstallTime = response.getInstallBeginTimestampSeconds();
boolean instantExperienceLaunched = response.getGooglePlayInstantParam();
주의: 설치 리퍼러 정보는 90일 동안 사용할 수 있으며 애플리케이션을 재설치하지 않는 한 변경되지 않습니다. 앱에서 불필요한 API 호출을 피하려면 설치 후 첫 실행 시 한 번만 API를 호출해야 합니다.
서비스 연결 종료
리퍼러 정보를 가져온 후 InstallReferrerClient
인스턴스의 endConnection()
메서드를 호출하여 연결을 종료합니다. 연결을 종료하면 누출 및 성능 문제를 방지할 수 있습니다.
자세한 내용은 Play 설치 리퍼러 라이브러리 참조를 확인하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","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-07-27(UTC)"],[],[],null,["# Play Install Referrer Library\n\nYou can use the Google Play Store's Install Referrer API to securely retrieve\nreferral content from Google Play. The Play Install Referrer API Client Library\nis written in the Java programming language and is a wrapper for the Android\nInterface Definition Language (AIDL) file that defines the interface to the\nInstall Referrer service. You can use the Play Install Referrer API Client\nLibrary to simplify your development process.\n\nThis guide covers the basics of retrieving referral information from Google\nPlay using the Play Install Referrer Library.\n| **Note:** If you are developing your app using a language other than the Kotlin programming language or the Java programming language, you can interact directly with the AIDL file by using the [Play Install Referrer\n| API](/google/play/installreferrer/igetinstallreferrerservice).\n\nUpdating your app's dependencies\n--------------------------------\n\nAdd the following line to the dependencies section of the `build.gradle` file\nfor your app: \n\n### Groovy\n\n```groovy\ndependencies {\n ...\n implementation \"com.android.installreferrer:installreferrer:2.2\"\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n ...\n implementation(\"com.android.installreferrer:installreferrer:2.2\")\n}\n```\n\nConnecting to Google Play\n-------------------------\n\nBefore you can use the Play Install Referrer API Library, you must\nestablish a connection to the Play Store app using the following\nsteps:\n\n1. Call the [`newBuilder()`](/reference/com/android/installreferrer/api/InstallReferrerClient#newBuilder(android.content.Context)) method to create an instance of [`InstallReferrerClient`](/reference/com/android/installreferrer/api/InstallReferrerClient) class.\n2. Call the\n [`startConnection()`](/reference/com/android/installreferrer/api/InstallReferrerClient#startConnection(com.android.installreferrer.api.InstallReferrerStateListener))\n to establish a connection to Google Play.\n\n3. The [`startConnection()`](/reference/com/android/installreferrer/api/InstallReferrerClient#startConnection(com.android.installreferrer.api.InstallReferrerStateListener))\n method is asynchronous, so you must override\n [`InstallReferrerStateListener`](/reference/com/android/installreferrer/api/InstallReferrerStateListener)\n to receive a callback after\n [`startConnection()`](/reference/com/android/installreferrer/api/InstallReferrerClient#startConnection(com.android.installreferrer.api.InstallReferrerStateListener))\n completes.\n\n4. Override the [`onInstallReferrerSetupFinished()`](/reference/com/android/installreferrer/api/InstallReferrerStateListener#onInstallReferrerSetupFinished(int))\n method to be notified when the callback completes. This method is called\n with a response code that you must use to handle the different states.\n [`OK`](https://developer.android.com/reference/com/android/installreferrer/api/InstallReferrerClient.InstallReferrerResponse#OK)\n indicates that the connection was successful. Each of the other\n [`InstallReferrerResponse`](/reference/com/android/installreferrer/api/InstallReferrerClient.InstallReferrerResponse)\n constants are for different types of errors.\n\n5. Override the [`onInstallReferrerServiceDisconnected()`](/reference/com/android/installreferrer/api/InstallReferrerStateListener#oninstallreferrerservicedisconnected)\n method to handle lost connections to Google Play. For\n example, the Play Install Referrer Library client may lose the connection if the\n Play Store service is updating in the background. The library client must call\n the\n [`startConnection()`](/reference/com/android/installreferrer/api/InstallReferrerClient#startConnection(com.android.installreferrer.api.InstallReferrerStateListener))\n method to restart the connection before making further requests.\n\nThe following code demonstrates how to start and test a connection to the\nPlay Store app: \n\n### Kotlin\n\n```kotlin\nprivate lateinit var referrerClient: InstallReferrerClient\n\nreferrerClient = InstallReferrerClient.newBuilder(this).build()\nreferrerClient.startConnection(object : InstallReferrerStateListener {\n\n override fun onInstallReferrerSetupFinished(responseCode: Int) {\n when (responseCode) {\n InstallReferrerResponse.OK -\u003e {\n // Connection established.\n }\n InstallReferrerResponse.FEATURE_NOT_SUPPORTED -\u003e {\n // API not available on the current Play Store app.\n }\n InstallReferrerResponse.SERVICE_UNAVAILABLE -\u003e {\n // Connection couldn't be established.\n }\n }\n }\n\n override fun onInstallReferrerServiceDisconnected() {\n // Try to restart the connection on the next request to\n // Google Play by calling the startConnection() method.\n }\n})\n```\n\n### Java\n\n```java\nInstallReferrerClient referrerClient;\n\nreferrerClient = InstallReferrerClient.newBuilder(this).build();\nreferrerClient.startConnection(new InstallReferrerStateListener() {\n @Override\n public void onInstallReferrerSetupFinished(int responseCode) {\n switch (responseCode) {\n case InstallReferrerResponse.OK:\n // Connection established.\n break;\n case InstallReferrerResponse.FEATURE_NOT_SUPPORTED:\n // API not available on the current Play Store app.\n break;\n case InstallReferrerResponse.SERVICE_UNAVAILABLE:\n // Connection couldn't be established.\n break;\n }\n }\n\n @Override\n public void onInstallReferrerServiceDisconnected() {\n // Try to restart the connection on the next request to\n // Google Play by calling the startConnection() method.\n }\n});\n```\n\nGetting the install referrer\n----------------------------\n\nAfter you have established a connection to the Play Store app, get the details\nfrom the install referrer by completing the following steps:\n\n1. Use the synchronized\n [`getInstallReferrer()`](/reference/com/android/installreferrer/api/InstallReferrerClient#getInstallReferrer())\n method to return an instance of\n [`ReferrerDetails`](/reference/com/android/installreferrer/api/ReferrerDetails).\n\n2. Use the methods that the\n [`ReferrerDetails`](/reference/com/android/installreferrer/api/ReferrerDetails)\n class provides to get details about the install referrer.\n\nThe following code demonstrates how you can access the install referrer\ninformation: \n\n### Kotlin\n\n```kotlin\nval response: ReferrerDetails = referrerClient.installReferrer\nval referrerUrl: String = response.installReferrer\nval referrerClickTime: Long = response.referrerClickTimestampSeconds\nval appInstallTime: Long = response.installBeginTimestampSeconds\nval instantExperienceLaunched: Boolean = response.googlePlayInstantParam\n```\n\n### Java\n\n```java\nReferrerDetails response = referrerClient.getInstallReferrer();\nString referrerUrl = response.getInstallReferrer();\nlong referrerClickTime = response.getReferrerClickTimestampSeconds();\nlong appInstallTime = response.getInstallBeginTimestampSeconds();\nboolean instantExperienceLaunched = response.getGooglePlayInstantParam();\n```\n\n**Caution:** The install referrer information will be\navailable for 90 days and **won't change** unless the application is\nreinstalled. To avoid unnecessary API calls in your app, you should invoke the\nAPI **only once** during the first execution after install.\n\nClosing service connection\n--------------------------\n\nAfter getting referrer information, call the\n[`endConnection()`](/reference/com/android/installreferrer/api/InstallReferrerClient#endConnection())\nmethod on your\n[`InstallReferrerClient`](/reference/com/android/installreferrer/api/InstallReferrerClient)\ninstance to close the connection. Closing the connection will help you avoid\nleaks and performance problems.\n\nFor further information, refer to the [Play Install Referrer Library\nReference](/reference/com/android/installreferrer/packages)."]]