Adapty Android SDK を v3.3 に移行する
Adapty SDK 3.3.0 はメジャーリリースであり、いくつかの改善が含まれていますが、移行手順が必要になる場合があります。
- ペイウォールビルダーで作成されていないペイウォールでの購入処理を更新してください。
USER_CANCELEDおよびPENDING_PURCHASEエラーコードの処理を停止してください。キャンセルされた購入はエラーとして扱われなくなり、エラーなしの購入結果として返されます。 - ペイウォールビルダーで作成されたペイウォールの
onPurchaseCanceledおよびonPurchaseSuccessイベントを、新しいonPurchaseFinishedイベントに置き換えてください。この変更も同じ理由です:キャンセルされた購入はエラーとして扱われなくなり、エラーなしの購入結果に含まれます。 - ペイウォールビルダーのペイウォールに対する
onAwaitingSubscriptionUpdateParamsのメソッドシグネチャを変更してください。 - ファイル URI を直接渡してフォールバックペイウォールを提供している場合は、その方法を更新してください。
- Adjust、AirBridge、Amplitude、AppMetrica、Appsflyer、Branch、Facebook Ads、Firebase and Google Analytics、Mixpanel、OneSignal、Pushwoosh のインテグレーション設定を更新してください。
購入処理の更新
以前は、キャンセルされた購入と保留中の購入はエラーとして扱われ、それぞれ USER_CANCELED および PENDING_PURCHASE コードが返されていました。
新しい AdaptyPurchaseResult クラスを使用して、キャンセル・成功・保留中の購入を示すようになりました。以下のように購入コードを更新してください:
Adapty.makePurchase(activity, product) { result ->
when (result) {
is AdaptyResult.Success -> {
- val info = result.value
- val profile = info?.profile
-
- if (profile?.accessLevels?.get("YOUR_ACCESS_LEVEL")?.isActive == true) {
- // Grant access to the paid features
- }
+ when (val purchaseResult = result.value) {
+ is AdaptyPurchaseResult.Success -> {
+ val profile = purchaseResult.profile
+ if (profile.accessLevels["YOUR_ACCESS_LEVEL"]?.isActive == true) {
+ // Grant access to the paid features
+ }
+ }
+
+ is AdaptyPurchaseResult.UserCanceled -> {
+ // Handle the case where the user canceled the purchase
+ }
+
+ is AdaptyPurchaseResult.Pending -> {
+ // Handle deferred purchases (e.g., the user will pay offline with cash
+ }
+ }
}
is AdaptyResult.Error -> {
val error = result.error
// Handle the error
}
}
}
完全なコード例については、モバイルアプリで購入する ページをご覧ください。
ペイウォールビルダーの購入イベントを変更する
-
onPurchaseFinishedイベントを追加します:+ public override fun onPurchaseFinished( + purchaseResult: AdaptyPurchaseResult, + product: AdaptyPaywallProduct, + context: Context, + ) { + when (purchaseResult) { + is AdaptyPurchaseResult.Success -> { + // Grant access to the paid features + } + is AdaptyPurchaseResult.UserCanceled -> { + // Handle the case where the user canceled the purchase + } + is AdaptyPurchaseResult.Pending -> { + // Handle deferred purchases (e.g., the user will pay offline with cash) + } + } + }完全なコード例については、成功・キャンセル・保留中の購入 とイベントの説明をご覧ください。
-
onPurchaseCancelledイベントの処理を削除します:- public override fun onPurchaseCanceled( - product: AdaptyPaywallProduct, - context: Context, - ) {} -
onPurchaseSuccessを削除します:- public override fun onPurchaseSuccess( - profile: AdaptyProfile?, - product: AdaptyPaywallProduct, - context: Context, - ) { - // Your logic on successful purchase - }
onAwaitingSubscriptionUpdateParams メソッドのシグネチャを変更する
別のサブスクリプションがアクティブな状態で新しいサブスクリプションが購入された場合、新しいサブスクリプションで既存のサブスクリプションを置き換えるには onSubscriptionUpdateParamsReceived(AdaptySubscriptionUpdateParameters...)) を、既存のサブスクリプションをアクティブに維持しながら新しいサブスクリプションを別途追加するには onSubscriptionUpdateParamsReceived(null) を呼び出してください:
- public override fun onAwaitingSubscriptionUpdateParams(
- product: AdaptyPaywallProduct,
- context: Context,
- ): AdaptySubscriptionUpdateParameters? {
- return AdaptySubscriptionUpdateParameters(...)
- }
+ public override fun onAwaitingSubscriptionUpdateParams(
+ product: AdaptyPaywallProduct,
+ context: Context,
+ onSubscriptionUpdateParamsReceived: SubscriptionUpdateParamsCallback,
+ ) {
+ onSubscriptionUpdateParamsReceived(AdaptySubscriptionUpdateParameters(...))
+ }
最終的なコード例については、サブスクリプションのアップグレード のドキュメントセクションをご覧ください。
フォールバックペイウォールの提供方法を更新する
フォールバックペイウォールを提供するためにファイル URI を渡している場合は、以下のように更新してください:
サードパーティインテグレーションの SDK 設定を更新する
Adapty Android SDK 3.3.0 以降でインテグレーションが正しく動作するように、以下のセクションに従って各インテグレーションの SDK 設定を更新してください。
Adjust
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、Adjust インテグレーションの SDK 設定 をご覧ください。
AirBridge
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、AirBridge インテグレーションの SDK 設定 をご覧ください。
Airbridge.getDeviceInfo().getUUID(object: AirbridgeCallback.SimpleCallback<String>() {
override fun onSuccess(result: String) {
- val params = AdaptyProfileParameters.Builder()
- .withAirbridgeDeviceId(result)
- .build()
- Adapty.updateProfile(params) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier("airbridge_device_id", result) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
}
override fun onFailure(throwable: Throwable) {
}
})
Amplitude
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、Amplitude インテグレーションの SDK 設定 をご覧ください。
// For Amplitude maintenance SDK (obsolete)
val amplitude = Amplitude.getInstance()
val amplitudeDeviceId = amplitude.getDeviceId()
val amplitudeUserId = amplitude.getUserId()
//for actual Amplitude Kotlin SDK
val amplitude = Amplitude(
Configuration(
apiKey = AMPLITUDE_API_KEY,
context = applicationContext
)
)
val amplitudeDeviceId = amplitude.store.deviceId
val amplitudeUserId = amplitude.store.userId
//
- val params = AdaptyProfileParameters.Builder()
- .withAmplitudeDeviceId(amplitudeDeviceId)
- .withAmplitudeUserId(amplitudeUserId)
- .build()
- Adapty.updateProfile(params) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier("amplitude_user_id", amplitudeUserId) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
+ Adapty.setIntegrationIdentifier("amplitude_device_id", amplitudeDeviceId) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
AppMetrica
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、AppMetrica インテグレーションの SDK 設定 をご覧ください。
val startupParamsCallback = object: StartupParamsCallback {
override fun onReceive(result: StartupParamsCallback.Result?) {
val deviceId = result?.deviceId ?: return
- val params = AdaptyProfileParameters.Builder()
- .withAppmetricaDeviceId(deviceId)
- .withAppmetricaProfileId("YOUR_ADAPTY_CUSTOMER_USER_ID")
- .build()
- Adapty.updateProfile(params) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier("appmetrica_device_id", deviceId) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
+
+ Adapty.setIntegrationIdentifier("appmetrica_profile_id", "YOUR_ADAPTY_CUSTOMER_USER_ID") { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
}
override fun onRequestError(
reason: StartupParamsCallback.Reason,
result: StartupParamsCallback.Result?
) {
// Handle the error
}
}
AppMetrica.requestStartupParams(context, startupParamsCallback, listOf(StartupParamsCallback.APPMETRICA_DEVICE_ID))
AppsFlyer
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、AppsFlyer インテグレーションの SDK 設定 をご覧ください。
val conversionListener: AppsFlyerConversionListener = object : AppsFlyerConversionListener {
override fun onConversionDataSuccess(conversionData: Map<String, Any>) {
- Adapty.updateAttribution(
- conversionData,
- AdaptyAttributionSource.APPSFLYER,
- AppsFlyerLib.getInstance().getAppsFlyerUID(context)
- ) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ val uid = AppsFlyerLib.getInstance().getAppsFlyerUID(context)
+ Adapty.setIntegrationIdentifier("appsflyer_id", uid) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
+ Adapty.updateAttribution(conversionData, "appsflyer") { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
}
}
Branch
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、Branch インテグレーションの SDK 設定 をご覧ください。
// Login and update attribution
Branch.getAutoInstance(this)
.setIdentity("YOUR_USER_ID") { referringParams, error ->
referringParams?.let { data ->
- Adapty.updateAttribution(data, AdaptyAttributionSource.BRANCH) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.updateAttribution(data, "branch") { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
}
}
// Logout
Branch.getAutoInstance(context).logout()
Facebook Ads
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、Facebook Ads インテグレーションの SDK 設定 をご覧ください。
- val builder = AdaptyProfileParameters.Builder()
- .withFacebookAnonymousId(AppEventsLogger.getAnonymousAppDeviceGUID(context))
-
- Adapty.updateProfile(builder.build()) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier(
+ "facebook_anonymous_id",
+ AppEventsLogger.getAnonymousAppDeviceGUID(context)
+ ) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
Firebase and Google Analytics
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、Firebase and Google Analytics インテグレーションの SDK 設定 をご覧ください。
Mixpanel
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、Mixpanel インテグレーションの SDK 設定 をご覧ください。
- val params = AdaptyProfileParameters.Builder()
- .withMixpanelUserId(mixpanelAPI.distinctId)
- .build()
-
- Adapty.updateProfile(params) { error ->
- if (error != null) {
- // Handle the error
- }
- }
+ Adapty.setIntegrationIdentifier("mixpanel_user_id", mixpanelAPI.distinctId) { error ->
+ if (error != null) {
+ // Handle the error
+ }
+ }
OneSignal
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、OneSignal インテグレーションの SDK 設定 をご覧ください。
Pushwoosh
以下のようにモバイルアプリのコードを更新してください。完全なコード例については、Pushwoosh インテグレーションの SDK 設定 をご覧ください。