Android SDK - 구성 방법 참조

문서

안드로이드 SDK - 설정 메서드 레퍼런스

Singular SDK는 SingularConfig 클래스를 통해 유연한 설정 시스템을 제공합니다. 이 문서에서는 사용 가능한 모든 구성 옵션과 SDK를 초기화할 때 이를 사용하는 방법을 설명합니다.

withCustomSdid

SingularConfig.withCustomSdid 메서드

엔터프라이즈 기능: 사용자 지정 Singular 디바이스 ID(SDID)와 이에 액세스할 핸들러를 설정합니다.

서명

public SingularConfig withCustomSdid(String customSdid, SDIDAccessorHandler accessorHandler)

사용 예

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withCustomSdid("custom-device-id-12345", new SDIDAccessorHandler() {
        @Override
        public void onSDIDAccessed(String sdid) {
            // Handle SDID access
            Log.d("Singular", "SDID accessed: " + sdid);
        }
    });

withCustomUserId

SingularConfig.withCustomUserId 메서드

초기화 중에 사용자 지정 사용자 ID를 설정합니다.

서명

public SingularConfig withCustomUserId(String customUserId)

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withCustomUserId("user_12345");

withDDLHandler

SingularConfig.withDDLHandler 메서드

디퍼드 딥링크에 대한 핸들러를 설정합니다.

시그니처

public SingularConfig withDDLHandler(DeferredDeepLinkHandler handler)

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withDDLHandler(new DeferredDeepLinkHandler() {
        @Override
        public void onResolved(String resolvedLink) {
            if (resolvedLink != null) {
                // Handle the deferred deep link
                Log.d("Singular", "Deferred deep link: " + resolvedLink);
            }
        }
    });

withDDLTimeoutInSec

SingularConfig.withDDLTimeoutInSec 메서드

디퍼드 딥링크 확인의 시간 제한을 초 단위로 설정합니다.

시그니처

public SingularConfig withDDLTimeoutInSec(long timeout)

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withDDLHandler(deferredDeepLinkHandler)
    .withDDLTimeoutInSec(10); // 10 seconds timeout

withESPDomains

SingularConfig.withESPDomains 메서드

이메일 캠페인의 어트리뷰션을 처리하기 위한 ESP(이메일 서비스 제공업체) 도메인 목록을 설정합니다.

서명

public SingularConfig withESPDomains(List espDomains)

사용 예시

Java
List<String> espDomains = new ArrayList<>();
espDomains.add("email.example.com");
espDomains.add("newsletter.example.com");

SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withESPDomains(espDomains);

withFacebookAppId

SingularConfig.withFacebookAppId 메서드

페이스북 어트리뷰션을 위한 페이스북 앱 ID를 설정합니다.

서명

public SingularConfig withFacebookAppId(String facebookAppId)

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withFacebookAppId("123456789012345");

withFCMDeviceToken

SingularConfig.withFCMDeviceToken 메서드

초기화 중에 파이어베이스 클라우드 메시징 디바이스 토큰을 설정합니다.

서명

public SingularConfig withFCMDeviceToken(String fcmDeviceToken)

사용 예제

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withFCMDeviceToken("eKh2BNP-Txy4XrjDGmw...");

withGlobalProperty

SingularConfig.withGlobalProperty 메서드

초기화 중에 모든 이벤트에 포함될 전역 속성을 설정합니다.

시그니처

public SingularConfig withGlobalProperty(String key, String value, boolean overrideExisting)

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withGlobalProperty("app_version", "2.1.0", true)
    .withGlobalProperty("user_type", "free", true);

withIMEI

SingularConfig.withIMEI 메서드

초기화 중 추적할 디바이스 IMEI를 설정합니다.

서명

public SingularConfig withIMEI(String imei)

사용 예시

Java
// Note: Requires READ_PHONE_STATE permission
String imei = null;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) 
        == PackageManager.PERMISSION_GRANTED) {
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    imei = telephonyManager.getDeviceId();
}

SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withIMEI(imei);

withLimitAdvertisingIdentifiers

SingularConfig.withLimitAdvertisingIdentifiers 메서드

초기화 중 광고 식별자의 사용을 제한합니다.

서명

public SingularConfig withLimitAdvertisingIdentifiers()

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withLimitAdvertisingIdentifiers();

withLimitDataSharing

SingularConfig.withLimitDataSharing 메서드

초기화 중 파트너 및 네트워크와의 데이터 공유를 제한할지 여부를 제어합니다.

서명

public SingularConfig withLimitDataSharing(boolean shouldLimitDataSharing)

사용 예제

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withLimitDataSharing(true);

withLogLevel

SingularConfig.withLogLevel 메서드

SDK 로그의 로그 레벨을 설정합니다.

시그니처

public SingularConfig withLogLevel(int level)

사용 예제

Java
import android.util.Log;

SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withLoggingEnabled()
    .withLogLevel(Log.VERBOSE); // Use Log.VERBOSE, Log.DEBUG, Log.INFO, Log.WARN, Log.ERROR

withLoggingEnabled

SingularConfig.withLoggingEnabled 메서드

SDK에 대한 로깅을 활성화합니다.

Signature

public SingularConfig withLoggingEnabled()

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withLoggingEnabled();

withOAIDCollection

SingularConfig.withOAIDCollection 메서드

중국 디바이스에 대한 OAID(익명 디바이스 식별자) 수집을 활성화합니다.

서명

public SingularConfig withOAIDCollection()

사용 예제

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withOAIDCollection();

withOpenURI

SingularConfig.withOpenURI 메서드

어트리뷰션을 위해 앱을 연 URI를 설정합니다.

시그니처

public SingularConfig withOpenURI(Uri openUri)

사용 예시

Java
// In your Activity's onCreate method
Uri data = getIntent().getData();
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withOpenURI(data);

위드푸시 알림 페이로드

SingularConfig.withPushNotificationPayload 메서드

푸시 알림 페이로드와 페이로드에서 딥링크를 추출할 경로를 설정합니다.

서명

public SingularConfig withPushNotificationPayload(Intent intent, String[] ... pushNotificationLinkPath)

사용 예시

Java
// In your Activity that handles push notifications
Intent intent = getIntent();
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withPushNotificationPayload(intent, new String[]{"singular_link"}, new String[]{"data", "deeplink"});

withSdidAccessorHandler

SingularConfig.withSdidAccessorHandler 메서드

엔터프라이즈 기능: Singular 장치 ID(SDID)에 액세스하는 핸들러를 설정합니다.

서명

public SingularConfig withSdidAccessorHandler(SDIDAccessorHandler accessorHandler)

사용 예제

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withSdidAccessorHandler(new SDIDAccessorHandler() {
        @Override
        public void onSDIDAccessed(String sdid) {
            // Handle SDID access
            Log.d("Singular", "SDID accessed: " + sdid);
        }
    });

withSessionTimeoutInSec

SingularConfig.withSessionTimeoutInSec 메서드

세션 타임아웃을 초 단위로 설정합니다.

시그니처

public SingularConfig withSessionTimeoutInSec(long timeout)

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withSessionTimeoutInSec(60); // 60 seconds timeout

withSingular 디바이스 어트리뷰션

SingularConfig.withSingular 디바이스 어트리뷰션 메서드

베타 기능: 디바이스 어트리뷰션 데이터를 사용할 수 있을 때 수신하는 핸들러 함수를 설정합니다.

시그니처

public SingularConfig withSingularDeviceAttribution(SingularDeviceAttributionHandler handler)

사용 예시

Java
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withSingularDeviceAttribution(new SingularDeviceAttributionHandler() {
        @Override
        public void onDeviceAttributionInfoReceived(Map deviceAttributionData) {
            // Handle device attribution data
            if (deviceAttributionData != null) {
                for (Object key : deviceAttributionData.keySet()) {
                    Log.d("Singular", key + ": " + deviceAttributionData.get(key));
                }
            }
        }
    });

withSingular링크

Singular컨피그.withSingular링크 메서드

확인된 링크에 대한 콜백으로 Singular 링크 처리를 설정합니다.

시그니처

public SingularConfig withSingularLink(Intent intent, SingularLinkHandler handler)
public SingularConfig withSingularLink(Intent intent, SingularLinkHandler handler, long shortlinkTimeoutSec)

사용 예시

Java
// In your Activity's onCreate method
Intent intent = getIntent();
SingularConfig config = new SingularConfig("API_KEY", "API_SECRET")
    .withSingularLink(intent, new SingularLinkHandler() {
        @Override
        public void onResolved(SingularLinkParams params) {
            if (params != null) {
                // Handle the deep link
                String deeplink = params.getDeeplink();
                if (deeplink != null) {
                    Log.d("Singular", "Deep link: " + deeplink);
                    // Navigate to the appropriate screen
                }
                
                // Get passthrough parameters
                String passthrough = params.getPassthrough();
                if (passthrough != null) {
                    Log.d("Singular", "Passthrough: " + passthrough);
                }
                
                // Check if this is a deferred deep link
                boolean isDeferred = params.isDeferred();
                Log.d("Singular", "Is deferred: " + isDeferred);
            }
        }
    }, 10); // 10 seconds timeout

전체 구성 예제

여러 구성 옵션 연결하기

다음은 Singular SDK를 초기화할 때 여러 구성 옵션을 함께 연결하는 방법을 보여주는 전체 예제입니다.

사용 예시

Java
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import com.singular.sdk.Singular;
import com.singular.sdk.SingularConfig;
import com.singular.sdk.SingularLinkHandler;
import com.singular.sdk.SingularLinkParams;
import com.singular.sdk.SingularDeviceAttributionHandler;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MainActivity extends Activity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // Get the intent that started this activity
        Intent intent = getIntent();
        
        // Initialize Singular SDK with advanced configuration
        SingularConfig config = new SingularConfig("SDK KEY", "YOUR_SECRET")
            // Enable logging for debugging
            .withLoggingEnabled()
            .withLogLevel(Log.DEBUG)
            
            // Set custom user ID if available
            .withCustomUserId("user_12345")
            
            // Configure session timeout
            .withSessionTimeoutInSec(60)
            
            // Set global properties for all events
            .withGlobalProperty("app_version", "2.1.0", true)
            .withGlobalProperty("user_type", "premium", true)
            
            // Handle deep links
            .withSingularLink(intent, new SingularLinkHandler() {
                @Override
                public void onResolved(SingularLinkParams params) {
                    if (params != null) {
                        String deeplink = params.getDeeplink();
                        if (deeplink != null) {
                            Log.d("Singular", "Deep link: " + deeplink);
                            // Navigate based on deep link
                        }
                    }
                }
            }, 10)
            
            // Handle deferred deep links
            .withDDLHandler(new DeferredDeepLinkHandler() {
                @Override
                public void onResolved(String resolvedLink) {
                    if (resolvedLink != null) {
                        Log.d("Singular", "Deferred deep link: " + resolvedLink);
                        // Handle deferred deep link
                    }
                }
            })
            .withDDLTimeoutInSec(5)
            
            // Get device attribution data
            .withSingularDeviceAttribution(new SingularDeviceAttributionHandler() {
                @Override
                public void onDeviceAttributionInfoReceived(Map deviceAttributionData) {
                    if (deviceAttributionData != null) {
                        for (Object key : deviceAttributionData.keySet()) {
                            Log.d("Singular", key + ": " + deviceAttributionData.get(key));
                        }
                    }
                }
            })
            
            // Facebook attribution
            .withFacebookAppId("123456789012345")
            
            // Configure data sharing limitations for privacy
            .withLimitDataSharing(true)
            .withLimitAdvertisingIdentifiers();
        
        // Initialize the SDK with the configuration
        Singular.init(this, config);
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        Singular.onActivityResumed();
    }
    
    @Override
    protected void onPause() {
        super.onPause();
        Singular.onActivityPaused();
    }
}